-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #793 Allow API access to Elide for services without user authe…
…ntication
- Loading branch information
1 parent
7b5e3f6
commit 037c337
Showing
4 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/test/java/com/faforever/api/security/FafAuthenticationConverterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.faforever.api.security; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.security.authentication.AbstractAuthenticationToken; | ||
import org.springframework.security.oauth2.jwt.Jwt; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class FafAuthenticationConverterTest { | ||
@Test | ||
void jwtWithUsernameShouldBeConvertedToUserToken() { | ||
Jwt jwt = new Jwt( | ||
"abc", | ||
null, | ||
null, | ||
Map.of( | ||
"alg", "RS256", | ||
"kid", "public:hydra.jwt.access-token", | ||
"typ", "JWT" | ||
), | ||
Map.of( | ||
"sub", "123", | ||
"scp", List.of(), | ||
"ext", Map.of( | ||
"username", "fafuser" | ||
) | ||
) | ||
); | ||
AbstractAuthenticationToken converted = new FafAuthenticationConverter().convert(jwt); | ||
assertTrue(converted instanceof FafUserAuthenticationToken); | ||
} | ||
@Test | ||
void jwtWithoutUsernameShouldBeConvertedToServiceToken() { | ||
Jwt jwt = new Jwt( | ||
"abc", | ||
null, | ||
null, | ||
Map.of( | ||
"alg", "RS256", | ||
"kid", "public:hydra.jwt.access-token", | ||
"typ", "JWT" | ||
), | ||
Map.of( | ||
"sub", "service", | ||
"scp", List.of(), | ||
"ext", Map.of() | ||
) | ||
); | ||
AbstractAuthenticationToken converted = new FafAuthenticationConverter().convert(jwt); | ||
assertTrue(converted instanceof FafServiceAuthenticationToken); | ||
} | ||
} |