Skip to content

Commit 3ca0012

Browse files
Theo-lbgCopilot
andcommitted
feat(test): refactor authentication to use values from application properties
Co-authored-by: Copilot <copilot@github.com>
1 parent 8e87ff6 commit 3ca0012

3 files changed

Lines changed: 15 additions & 9 deletions

File tree

.github/workflows/sonar.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ jobs:
3737
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
3838
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
3939
run: |
40-
mkdir -p src/test/resources
41-
echo ${{ secrets.APPLICATION_TEST_PROPERTIES }} | base64 -d > src/test/resources/application-test.properties
40+
if [ -n "${{ secrets.APPLICATION_TEST_PROPERTIES }}" ]; then
41+
printf '%s' "${{ secrets.APPLICATION_TEST_PROPERTIES }}" | base64 -d >> src/test/resources/application-test.properties
42+
fi
4243
echo "spring.sql.init.mode=never" >> src/test/resources/application-test.properties
4344
mvn clean verify sonar:sonar -DskipDocker=true -Dsonar.qualitygate.wait=true -Dit.test="!CucumberIntegrationTest"

.github/workflows/tests.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ jobs:
3131

3232
- name: Prepare test properties
3333
run: |
34-
mkdir -p src/test/resources
35-
echo ${{ secrets.APPLICATION_TEST_PROPERTIES }} | base64 -d > src/test/resources/application-test.properties
34+
if [ -n "${{ secrets.APPLICATION_TEST_PROPERTIES }}" ]; then
35+
printf '%s' "${{ secrets.APPLICATION_TEST_PROPERTIES }}" | base64 -d >> src/test/resources/application-test.properties
36+
fi
3637
echo "spring.sql.init.mode=never" >> src/test/resources/application-test.properties
3738
3839
- name: Prepare Docker .env for CI tests

src/test/java/feature/SpringIntegrationTest.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.springframework.boot.resttestclient.autoconfigure.AutoConfigureTestRestTemplate;
88
import org.springframework.boot.test.context.SpringBootTest;
99
import org.springframework.boot.test.web.server.LocalServerPort;
10+
import org.springframework.beans.factory.annotation.Value;
1011
import org.springframework.http.HttpEntity;
1112
import org.springframework.http.HttpHeaders;
1213
import org.springframework.http.HttpMethod;
@@ -27,8 +28,11 @@
2728
)
2829
public class SpringIntegrationTest {
2930

30-
private static final String TEST_USERNAME = "testadmin";
31-
private static final String TEST_PASSWORD = "testadminpass";
31+
@Value("${app.security.admin.username}")
32+
private String testUsername;
33+
34+
@Value("${app.security.admin.password}")
35+
private String testPassword;
3236

3337
@Autowired
3438
protected TestRestTemplate restTemplate;
@@ -41,7 +45,7 @@ public class SpringIntegrationTest {
4145
protected void executeGet(String path) {
4246
String url = "http://localhost:" + port + path;
4347
latestResponse = restTemplate
44-
.withBasicAuth(TEST_USERNAME, TEST_PASSWORD)
48+
.withBasicAuth(testUsername, testPassword)
4549
.getForEntity(url, String.class);
4650
}
4751

@@ -51,14 +55,14 @@ protected void executePost(String path, Object payload) {
5155
headers.setContentType(MediaType.APPLICATION_JSON);
5256
HttpEntity<Object> request = new HttpEntity<>(payload, headers);
5357
latestResponse = restTemplate
54-
.withBasicAuth(TEST_USERNAME, TEST_PASSWORD)
58+
.withBasicAuth(testUsername, testPassword)
5559
.postForEntity(url, request, String.class);
5660
}
5761

5862
protected void executeDelete(String path) {
5963
String url = "http://localhost:" + port + path;
6064
latestResponse = restTemplate
61-
.withBasicAuth(TEST_USERNAME, TEST_PASSWORD)
65+
.withBasicAuth(testUsername, testPassword)
6266
.exchange(url, HttpMethod.DELETE, HttpEntity.EMPTY, String.class);
6367
}
6468
}

0 commit comments

Comments
 (0)