Skip to content

Commit

Permalink
Adds test profile classes to avoid nonexisting GetAuthenticatedToken …
Browse files Browse the repository at this point in the history
…bean in test context.
  • Loading branch information
rfc3092 committed Feb 17, 2025
1 parent 3eb5138 commit 4d90479
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;
import org.springframework.util.Assert;

@AutoConfiguration(after = ClientCredentialAutoConfiguration.class)
public class TokenServiceAutoConfiguration {
Expand All @@ -25,10 +24,9 @@ public class TokenServiceAutoConfiguration {
@Bean
@Profile("test")
AzureTokenService azureAdTokenServiceTest(
AzureClientCredential clientCredential,
GetAuthenticatedToken getAuthenticatedToken
AzureClientCredential clientCredential
) {
return new AzureTokenService(null, clientCredential, getAuthenticatedToken);
return new AzureTokenService.Test(clientCredential);
}

@Bean
Expand All @@ -47,7 +45,7 @@ AzureTokenService azureAdTokenService(
AzureNavTokenService azureNavTokenServiceTest(
AzureNavClientCredential azureNavClientCredential
) {
return new AzureNavTokenService(null, azureNavClientCredential);
return new AzureNavTokenService.Test(azureNavClientCredential);
}

@Bean
Expand All @@ -63,11 +61,9 @@ AzureNavTokenService azureNavTokenService(
@Bean
@Profile("test")
AzureTrygdeetatenTokenService trygdeetatenAzureAdTokenServiceTest(
AzureTrygdeetatenClientCredential clientCredential,
GetAuthenticatedUserId getAuthenticatedUserId,
ObjectMapper objectMapper
AzureTrygdeetatenClientCredential clientCredential
) {
return new AzureTrygdeetatenTokenService(null, clientCredential, getAuthenticatedUserId, objectMapper);
return new AzureTrygdeetatenTokenService.Test(clientCredential);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,21 @@ public Mono<AccessToken> exchange(ServerProperties serverProperties) {
).call();

}

/**
* Replaces {@link AzureNavTokenService} in test profile.
*/
public static class Test extends AzureNavTokenService {

public Test(AzureNavClientCredential clientCredential) {
super(null, clientCredential);
}

@Override
public Mono<AccessToken> exchange(ServerProperties serverProperties) {
return Mono.empty();
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,21 @@ private Mono<AccessToken> generateOnBehalfOfAccessToken(Token token, ServerPrope
token
).call();
}

/**
* Replaces {@link AzureTokenService} in test profile.
*/
public static class Test extends AzureTokenService {

public Test(AzureClientCredential clientCredential) {
super(null, clientCredential, null);
}

@Override
public Mono<AccessToken> exchange(ServerProperties serverProperties) {
return Mono.empty();
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,20 @@ private boolean expires(AccessToken accessToken) {
.minusSeconds(300)
.isBefore(Instant.now());
}

/**
* Replaces {@link AzureTrygdeetatenTokenService} in test profile.
*/
public static class Test extends AzureTrygdeetatenTokenService {

public Test(AzureTrygdeetatenClientCredential clientCredential) {
super(null, clientCredential, null, null);
}

@Override
public Mono<AccessToken> exchange(ServerProperties serverProperties) {
return Mono.empty();
}
}

}

0 comments on commit 4d90479

Please sign in to comment.