-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
74 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...eportportal/example/testng/logback/logging/restassured/RestAssuredSimpleSanitizeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2022 EPAM Systems | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.epam.reportportal.example.testng.logback.logging.restassured; | ||
|
||
import com.epam.reportportal.listeners.LogLevel; | ||
import com.epam.reportportal.restassured.ReportPortalRestAssuredLoggingFilter; | ||
import io.restassured.RestAssured; | ||
import io.restassured.config.LogConfig; | ||
import io.restassured.config.RestAssuredConfig; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* An example of a header credentials hiding in case they contain sensitive data. | ||
*/ | ||
public class RestAssuredSimpleSanitizeTest { | ||
|
||
/** | ||
* Create Rest Assured Logging Config with hidden headers. | ||
*/ | ||
private static final RestAssuredConfig CONFIG = RestAssuredConfig.config() | ||
.logConfig(LogConfig.logConfig().blacklistHeader("Authorization")); | ||
|
||
/** | ||
* Set {@link ReportPortalRestAssuredLoggingFilter} as one of the REST Assured filters. | ||
*/ | ||
@BeforeClass | ||
public void setupRestAssured() { | ||
RestAssured.reset(); // Reset everything to avoid collisions with other REST Assured examples | ||
RestAssured.filters(new ReportPortalRestAssuredLoggingFilter(42, LogLevel.INFO)); | ||
} | ||
|
||
/** | ||
* Make a simple request to a test API and validate the response. Sanitized Request / Response logs should appear on Report Portal. | ||
*/ | ||
@Test | ||
public void restAssuredLoggingTest() { | ||
RestAssured.given() | ||
.config(CONFIG) | ||
.header("Authorization", "Bearer test_token") | ||
.get("https://jsonplaceholder.typicode.com/todos/1") | ||
.then() | ||
.assertThat() | ||
.statusCode(200); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters