Skip to content

Commit

Permalink
BUGFIX: WA-14110 Fix failing sonar scan
Browse files Browse the repository at this point in the history
  • Loading branch information
thaoctthanh committed Jun 2, 2022
1 parent fcd95a7 commit c679e46
Show file tree
Hide file tree
Showing 19 changed files with 39 additions and 35 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@
<artifactId>httpcore</artifactId>
<version>4.4.14</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2021 GoodData Corporation.
* (C) 2022 GoodData Corporation.
* This source code is licensed under the BSD-style license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2021 GoodData Corporation.
* (C) 2022 GoodData Corporation.
* This source code is licensed under the BSD-style license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
Expand All @@ -8,8 +8,6 @@
import static com.gooddata.http.client.LoginSSTRetrievalStrategy.LOGIN_URL;
import static org.apache.commons.lang3.Validate.notNull;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2021 GoodData Corporation.
* (C) 2022 GoodData Corporation.
* This source code is licensed under the BSD-style license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/gooddata/http/client/JsonUtils.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/*
* (C) 2021 GoodData Corporation.
* (C) 2022 GoodData Corporation.
* This source code is licensed under the BSD-style license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
package com.gooddata.http.client;

import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.text.StringEscapeUtils;

/**
* Internal JSON helper
*/
class JsonUtils {

private JsonUtils() {}

static String createLoginJson(final String login, final String password, final int verificationLevel) {
return "{\"postUserLogin\":{\"login\":\"" + StringEscapeUtils.escapeJava(login) +
"\",\"password\":\"" + StringEscapeUtils.escapeJava(password) + "\",\"remember\":0" +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2021 GoodData Corporation.
* (C) 2022 GoodData Corporation.
* This source code is licensed under the BSD-style license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2021 GoodData Corporation.
* (C) 2022 GoodData Corporation.
* This source code is licensed under the BSD-style license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2021 GoodData Corporation.
* (C) 2022 GoodData Corporation.
* This source code is licensed under the BSD-style license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
Expand All @@ -8,7 +8,6 @@
import static org.apache.commons.lang3.Validate.notNull;

import org.apache.http.HttpHost;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;

import java.io.IOException;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/gooddata/http/client/TokenUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2021 GoodData Corporation.
* (C) 2022 GoodData Corporation.
* This source code is licensed under the BSD-style license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
Expand All @@ -17,6 +17,8 @@
*/
class TokenUtils {

private TokenUtils() {}

static String extractSST(final HttpResponse response) {
return extractToken(response, SST_HEADER);
}
Expand Down
10 changes: 2 additions & 8 deletions src/test/java/com/gooddata/http/client/GoodDataHttpClientAT.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2021 GoodData Corporation.
* (C) 2022 GoodData Corporation.
* This source code is licensed under the BSD-style license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
Expand All @@ -9,18 +9,11 @@
import static com.gooddata.http.client.TestUtils.getForEntity;
import static com.gooddata.http.client.TestUtils.logout;
import static com.gooddata.http.client.TestUtils.performGet;
import static org.junit.Assert.assertEquals;

import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.junit.Test;

import java.io.IOException;
Expand All @@ -31,6 +24,7 @@
* Acceptance tests. Requires GoodData credentials.<br/>
* <code>mvn -Pat clean verify [email protected] -DGDC_PASSWORD=password [-DGDC_BACKEND=<backend host>]</code>
*/
@SuppressWarnings("squid:S2699")
public class GoodDataHttpClientAT {

private static final String GDC_PROJECTS_PATH = "/gdc/projects";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2021 GoodData Corporation.
* (C) 2022 GoodData Corporation.
* This source code is licensed under the BSD-style license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
Expand Down Expand Up @@ -36,6 +36,7 @@
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;

@SuppressWarnings("squid:S2699")
public class GoodDataHttpClientIntegrationTest {

private static final String GDC_TOKEN_PATH = "/gdc/account/token";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2021 GoodData Corporation.
* (C) 2022 GoodData Corporation.
* This source code is licensed under the BSD-style license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2021 GoodData Corporation.
* (C) 2022 GoodData Corporation.
* This source code is licensed under the BSD-style license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/gooddata/http/client/JsonUtilsTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2021 GoodData Corporation.
* (C) 2022 GoodData Corporation.
* This source code is licensed under the BSD-style license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/*
* (C) 2021 GoodData Corporation.
* (C) 2022 GoodData Corporation.
* This source code is licensed under the BSD-style license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
package com.gooddata.http.client;

import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
Expand All @@ -17,15 +16,16 @@
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.message.BasicStatusLine;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;

import org.mockito.MockitoAnnotations;
import org.slf4j.Logger;

Expand Down Expand Up @@ -53,6 +53,7 @@ public class LoginSSTRetrievalStrategyTest {
private static final String TT = "xxxtopsecretTT";

private LoginSSTRetrievalStrategy sstStrategy;
private AutoCloseable mockClass;

@Mock
public HttpClient httpClient;
Expand All @@ -69,11 +70,15 @@ public class LoginSSTRetrievalStrategyTest {

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mockClass = MockitoAnnotations.openMocks(this);
host = new HttpHost("server.com", 123);
sstStrategy = new LoginSSTRetrievalStrategy(LOGIN, PASSWORD);
}

@After
public void tearDown() throws Exception {
mockClass.close();
}
@Test
public void obtainSstHeader() throws IOException {
statusLine = new BasicStatusLine(new ProtocolVersion("https", 1, 1), HttpStatus.SC_OK, "OK");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2021 GoodData Corporation.
* (C) 2022 GoodData Corporation.
* This source code is licensed under the BSD-style license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
Expand All @@ -9,7 +9,7 @@

import org.junit.Test;


@SuppressWarnings("squid:S2699")
public class SimpleSSTRetrievalStrategyTest {

public static final String TOKEN = "sst token";
Expand Down
4 changes: 1 addition & 3 deletions src/test/java/com/gooddata/http/client/TestUtils.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
/*
* (C) 2021 GoodData Corporation.
* (C) 2022 GoodData Corporation.
* This source code is licensed under the BSD-style license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
package com.gooddata.http.client;

import static org.junit.Assert.assertEquals;

import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/gooddata/http/client/TokenUtilsTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2021 GoodData Corporation.
* (C) 2022 GoodData Corporation.
* This source code is licensed under the BSD-style license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/log4j.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# (C) 2021 GoodData Corporation.
# (C) 2022 GoodData Corporation.
# This source code is licensed under the BSD-style license found in the
# LICENSE.txt file in the root directory of this source tree.
#
Expand Down

0 comments on commit c679e46

Please sign in to comment.