Skip to content

Commit

Permalink
Fix Cookies logging on requests
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Apr 2, 2024
1 parent 606fe79 commit f5c56dd
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

## [Unreleased]
### Fixed
- Cookies logging on requests, by @HardNorth

## [5.2.9]
### Changed
Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ dependencies {
implementation "org.aspectj:aspectjrt:${project.aspectj_version}"
implementation "org.aspectj:aspectjweaver:${project.aspectj_version}"

implementation 'org.slf4j:slf4j-api:2.0.7'
implementation "org.slf4j:slf4j-api:${slf4j_version}"

testImplementation "org.slf4j:jul-to-slf4j:${slf4j_version}"
testImplementation("org.junit.platform:junit-platform-runner:${project.junit_runner_version}") {
exclude module: 'junit'
}
Expand All @@ -80,6 +81,7 @@ dependencies {
}
testImplementation 'org.apache.commons:commons-io:1.3.2'
testImplementation 'com.epam.reportportal:agent-java-test-utils:0.0.3'

}

test {
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ scripts_url=https://raw.githubusercontent.com/reportportal/gradle-scripts
scripts_branch=develop
excludeTests=
aspectj_version=1.9.19
slf4j_version=2.0.7
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ protected OkHttpClient defaultClient(@Nonnull ListenerParameters parameters) {
if (parameters.isHttpLogging()) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
builder.addInterceptor(logging);
builder.addNetworkInterceptor(logging);
}

ofNullable(parameters.getHttpCallTimeout()).ifPresent(builder::callTimeout);
Expand Down
30 changes: 18 additions & 12 deletions src/test/java/com/epam/reportportal/service/ReportPortalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
package com.epam.reportportal.service;

import com.epam.reportportal.listeners.ListenerParameters;
import com.epam.reportportal.util.test.SocketUtils;
import com.epam.reportportal.test.TestUtils;
import com.epam.reportportal.util.test.CommonUtils;
import com.epam.reportportal.util.test.SocketUtils;
import com.epam.ta.reportportal.ws.model.FinishExecutionRQ;
import com.epam.ta.reportportal.ws.model.StartTestItemRQ;
import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ;
Expand All @@ -31,6 +31,7 @@
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.slf4j.bridge.SLF4JBridgeHandler;

import java.net.ServerSocket;
import java.nio.charset.StandardCharsets;
Expand All @@ -50,6 +51,11 @@
import static org.mockito.Mockito.*;

public class ReportPortalTest {
static {
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
}

private static final String COOKIE = "AWSALB=P7cqG8g/K70xHAKOUPrWrG0XgmhG8GJNinj8lDnKVyITyubAen2lBr+fSa/e2JAoGksQphtImp49rZxc41qdqUGvAc67SdZHY1BMFIHKzc8kyWc1oQjq6oI+s39U";

@Mock
Expand Down Expand Up @@ -88,9 +94,10 @@ public void verify_correct_url_results_in_correct_launch() {

@Test
public void verify_proxy_parameter_works() throws Exception {
String baseUrl = "http://example.com:8080";
ServerSocket server = SocketUtils.getServerSocketOnFreePort();
ListenerParameters params = standardParameters();
@SuppressWarnings("HttpUrlsUsage")
String baseUrl = "http://example.com:8080";
params.setBaseUrl(baseUrl);
params.setProxyUrl("http://localhost:" + server.getLocalPort());
OkHttpClient client = ReportPortal.builder().defaultClient(params);
Expand All @@ -116,14 +123,15 @@ public void verify_proxy_parameter_works() throws Exception {

@Test
public void verify_proxy_credential_works() throws Exception {
String baseUrl = "http://example.com:8080";
String userName = "user";
String password = "password";
String expectedAuth = "Authorization: Basic "
+ Base64.getEncoder().encodeToString((userName + ":" + password).getBytes(StandardCharsets.UTF_8))
+ System.lineSeparator();
String expectedAuth =
"Authorization: Basic " + Base64.getEncoder().encodeToString((userName + ":" + password).getBytes(StandardCharsets.UTF_8))
+ System.lineSeparator();
ServerSocket server = SocketUtils.getServerSocketOnFreePort();
ListenerParameters params = standardParameters();
@SuppressWarnings("HttpUrlsUsage")
String baseUrl = "http://example.com:8080";
params.setBaseUrl(baseUrl);
params.setProxyUrl("http://localhost:" + server.getLocalPort());
params.setProxyUser(userName);
Expand Down Expand Up @@ -155,10 +163,10 @@ public void verify_proxy_credential_works() throws Exception {
public void verify_rp_client_saves_and_bypasses_cookies() throws Exception {
ServerSocket ss = SocketUtils.getServerSocketOnFreePort();
ListenerParameters parameters = standardParameters();
parameters.setHttpLogging(true);
parameters.setBaseUrl("http://localhost:" + ss.getLocalPort());
ExecutorService clientExecutor = Executors.newSingleThreadExecutor();
ReportPortalClient rpClient = ReportPortal.builder()
.buildClient(ReportPortalClient.class, parameters, clientExecutor);
ReportPortalClient rpClient = ReportPortal.builder().buildClient(ReportPortalClient.class, parameters, clientExecutor);
Exception error = null;
try {
Map<String, Object> model = new HashMap<>();
Expand All @@ -170,10 +178,7 @@ public void verify_rp_client_saves_and_bypasses_cookies() throws Exception {
cal.add(Calendar.MINUTE, 2);
model.put("expire", sdf.format(cal.getTime()));

SocketUtils.ServerCallable serverCallable = new SocketUtils.ServerCallable(ss,
model,
"files/socket_response.txt"
);
SocketUtils.ServerCallable serverCallable = new SocketUtils.ServerCallable(ss, model, "files/socket_response.txt");
Callable<StartLaunchRS> clientCallable = () -> rpClient.startLaunch(new StartLaunchRQ())
.timeout(5, TimeUnit.SECONDS)
.blockingGet();
Expand Down Expand Up @@ -233,6 +238,7 @@ public void verify_launch_uuid_parameter_handling() {
Maybe<String> launchMaybe = launch.start();
assertThat(launchMaybe.blockingGet(), equalTo(launchUuid));

//noinspection ReactiveStreamsUnusedPublisher
launch.startTestItem(TestUtils.standardStartSuiteRequest());

verify(rpClient, timeout(1000).times(0)).startLaunch(any(StartLaunchRQ.class));
Expand Down

0 comments on commit f5c56dd

Please sign in to comment.