Skip to content

Commit

Permalink
Update Rest Assured examples
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Dec 2, 2024
1 parent d41205f commit a1e39df
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/**
* An example of a header, cookies and URI credentials hiding in case they contain sensitive data.
*/
public class RestAssuredSanitizeTest {
public class RestAssuredAdvanceSanitizeTest {

/**
* Set {@link ReportPortalRestAssuredLoggingFilter} as one of the REST Assured filters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ public void restAssuredLoggingTest() {
.post("https://example.com/api/test")
.then()
.assertThat()
.statusCode(404);
.statusCode(405);
}
}
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);
}
}
15 changes: 12 additions & 3 deletions example-testng-logback/suites/logging_tests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,19 @@
<class name="com.epam.reportportal.example.testng.logback.logging.restassured.RestAssuredBasicLoggingTest" />
</classes>
</test>
<test name="REST Assured request sanitizing test">
<test name="REST Assured Form request logging test">
<classes>
<class name="com.epam.reportportal.example.testng.logback.logging.restassured.RestAssuredSanitizeTest" />
<class name="com.epam.reportportal.example.testng.logback.logging.restassured.RestAssuredFormTest" />
</classes>
</test>
<test name="REST Assured simple request headers sanitizing test">
<classes>
<class name="com.epam.reportportal.example.testng.logback.logging.restassured.RestAssuredAdvanceSanitizeTest" />
</classes>
</test>
<test name="REST Assured advance request sanitizing test">
<classes>
<class name="com.epam.reportportal.example.testng.logback.logging.restassured.RestAssuredAdvanceSanitizeTest" />
</classes>
</test>

</suite>

0 comments on commit a1e39df

Please sign in to comment.