-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec3938a
commit 2401b9d
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/test/java/eu/dissco/orchestration/backend/security/JwtAuthConverterTest.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,58 @@ | ||
package eu.dissco.orchestration.backend.security; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.time.Instant; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.security.oauth2.jwt.Jwt; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class JwtAuthConverterTest { | ||
|
||
private JwtAuthConverter converter; | ||
|
||
@BeforeEach | ||
void setup() { | ||
converter = new JwtAuthConverter(); | ||
} | ||
|
||
@Test | ||
void testEmptyToken() { | ||
// Given | ||
var jwt = new Jwt("SomeRandomStringWithTheFullValue", Instant.now(), Instant.now(), | ||
Map.of("kid", "SomeRandom", "typ", "JWT", "alg", "RS256"), | ||
Map.of("sub", "adf294ba-bb03-4962-8042-a37f1648458e")); | ||
|
||
// When | ||
var token = converter.convert(jwt); | ||
|
||
// Then | ||
assertThat(token.isAuthenticated()).isTrue(); | ||
assertThat(token.getName()).isEqualTo("adf294ba-bb03-4962-8042-a37f1648458e"); | ||
assertThat(token.getAuthorities()).isEmpty(); | ||
} | ||
|
||
@Test | ||
void testTokenRoles() { | ||
// Given | ||
var jwt = new Jwt("SomeRandomStringWithTheFullValue", Instant.now(), Instant.now(), | ||
Map.of("kid", "SomeRandom", "typ", "JWT", "alg", "RS256"), | ||
Map.of("sub", "adf294ba-bb03-4962-8042-a37f1648458e", | ||
"resource_access", Map.of("orchestration-service", | ||
Map.of("roles", List.of("orchestration-admin"))))); | ||
|
||
// When | ||
var token = converter.convert(jwt); | ||
|
||
// Then | ||
assertThat(token.isAuthenticated()).isTrue(); | ||
assertThat(token.getName()).isEqualTo("adf294ba-bb03-4962-8042-a37f1648458e"); | ||
assertThat(token.getAuthorities()).hasSize(1); | ||
} | ||
|
||
} |