Skip to content

Commit a4e91ee

Browse files
authored
Merge pull request #9 from entur/bugfix/SIK-1501
SIK-1501: Fix TenantAnnotationTokenFactory don't handle PortReservation correct
2 parents 290ae01 + 9c386b8 commit a4e91ee

File tree

7 files changed

+20
-15
lines changed

7 files changed

+20
-15
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# [Release notes](https://github.com/entur/oidc-auth-client)
22

3+
## oidc-auth-resource-server v1.0.1
4+
* Fix TenantAnnotationTokenFactory don't handle PortReservation correct
5+
36
## oidc-auth-resource-server v1.0.0
47
* oidc-auth-resource-server are split out as separate project from oidc-auth

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
group=org.entur.auth.resource-server
2-
version=1.1.0-SNAPSHOT
2+
version=1.0.1-SNAPSHOT
33

44
org.gradle.jvmargs=-Xms128m -Xmx2048m

oidc-rs-junit-tenant/src/main/java/org/entur/auth/junit/tenant/TenantAnnotationTokenFactory.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* </ul>
3333
*/
3434
@Slf4j
35-
public class TenantAnnotationTokenFactory {
35+
public class TenantAnnotationTokenFactory implements AutoCloseable {
3636
private final Provider provider;
3737
private final PortReservation portReservation;
3838
private JwtTokenFactory jwtTokenFactory;
@@ -61,9 +61,7 @@ public void setServer(@NonNull WireMockAuthenticationServer server) {
6161
return;
6262
}
6363

64-
if (this.server != null) {
65-
this.server.close();
66-
}
64+
close();
6765

6866
log.info("Setup mock server on port {}", portReservation.getPort());
6967
this.jwtTokenFactory = new JwtTokenFactory(provider);
@@ -75,19 +73,23 @@ public void setServer(@NonNull WireMock wireMock, int port) {
7573
return;
7674
}
7775

78-
if (this.server != null) {
79-
this.server.close();
80-
}
76+
close();
8177

82-
log.info("Setup mock server on port {}", portReservation.getPort());
78+
log.info("Setup mock server on port {}", port);
8379
this.jwtTokenFactory = new JwtTokenFactory(provider);
8480
this.server = new WireMockAuthenticationServer(wireMock, port);
8581
}
8682

87-
public void shutdown() {
83+
public void close() {
84+
if (this.server == null) {
85+
return;
86+
}
87+
8888
this.server.close();
89+
if (this.server.getPort() == this.portReservation.getPort()) {
90+
this.portReservation.start();
91+
}
8992
this.server = null;
90-
this.portReservation.start();
9193
}
9294

9395
/**

oidc-rs-junit-tenant/src/test/java/org/entur/auth/junit/tenant/WireMockTestAnnotationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ void testTokenExists(@PartnerTenant(clientId = "abc", username = "testUser") Str
2828

2929
@AfterAll
3030
static void aferAllTests(TenantAnnotationTokenFactory annotationTokenFactory) {
31-
annotationTokenFactory.shutdown();
31+
annotationTokenFactory.close();
3232
}
3333
}

oidc-rs-spring-boot-web-test/src/test/java/org/entur/auth/spring/test/server/WireMockTestAnnotationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,6 @@ void testProtectedWithPartner(
6565

6666
@AfterAll
6767
static void aferAllTests(TenantAnnotationTokenFactory annotationTokenFactory) {
68-
annotationTokenFactory.shutdown();
68+
annotationTokenFactory.close();
6969
}
7070
}

oidc-rs-spring-boot-web-test/src/test/resources/config/application-annotation.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ entur:
1010
- /unprotected
1111
tenants:
1212
environment: dev
13-
include: partner
13+
include: []

oidc-rs-spring-boot-webflux-test/src/test/java/org/entur/auth/spring/test/server/ReactiveWireMockTestAnnotationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ void testProtectedWithPartner(
6767

6868
@AfterAll
6969
static void aferAllTests(TenantAnnotationTokenFactory annotationTokenFactory) {
70-
annotationTokenFactory.shutdown();
70+
annotationTokenFactory.close();
7171
}
7272
}

0 commit comments

Comments
 (0)