This repository has been archived by the owner on Aug 25, 2024. It is now read-only.
forked from LangStream/langstream
-
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.
fix: support old jwt configuration params (#123)
- Loading branch information
1 parent
9e3b7a0
commit 17bf492
Showing
3 changed files
with
90 additions
and
7 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
77 changes: 77 additions & 0 deletions
77
...langstream/apigateway/auth/impl/jwt/admin/JwtAuthenticationProviderConfigurationTest.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,77 @@ | ||
package ai.langstream.apigateway.auth.impl.jwt.admin; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
import lombok.SneakyThrows; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class JwtAuthenticationProviderConfigurationTest { | ||
|
||
protected static final ObjectMapper yamlConfigReader = new ObjectMapper(new YAMLFactory()); | ||
|
||
@Test | ||
void parseCamelCase() { | ||
final String yaml = """ | ||
adminRoles: | ||
- admin | ||
- super-admin | ||
audience: a | ||
audienceClaim: aud | ||
authClaim: role | ||
publicAlg: RS256 | ||
publicKey: --key-- | ||
secretKey: --skey-- | ||
jwksHostsAllowlist: https://localhost | ||
"""; | ||
final JwtAuthenticationProviderConfiguration tokenProperties = parse(yaml); | ||
assertEquals(List.of("admin", "super-admin"), tokenProperties.adminRoles()); | ||
assertEquals("a", tokenProperties.audience()); | ||
assertEquals("aud", tokenProperties.audienceClaim()); | ||
assertEquals("role", tokenProperties.authClaim()); | ||
assertEquals("RS256", tokenProperties.publicAlg()); | ||
assertEquals("--key--", tokenProperties.publicKey()); | ||
assertEquals("https://localhost", tokenProperties.jwksHostsAllowlist()); | ||
assertEquals("--skey--", tokenProperties.secretKey()); | ||
} | ||
|
||
@Test | ||
void parseKebabCase() { | ||
final String yaml = """ | ||
admin-roles: | ||
- admin | ||
- super-admin | ||
audience: a | ||
audience-claim: aud | ||
auth-claim: role | ||
public-alg: RS256 | ||
public-key: --key-- | ||
secret-key: --skey-- | ||
jwks-hosts-allowlist: https://localhost | ||
"""; | ||
final JwtAuthenticationProviderConfiguration tokenProperties = parse(yaml); | ||
assertEquals(List.of("admin", "super-admin"), tokenProperties.adminRoles()); | ||
assertEquals("a", tokenProperties.audience()); | ||
assertEquals("aud", tokenProperties.audienceClaim()); | ||
assertEquals("role", tokenProperties.authClaim()); | ||
assertEquals("RS256", tokenProperties.publicAlg()); | ||
assertEquals("--key--", tokenProperties.publicKey()); | ||
assertEquals("https://localhost", tokenProperties.jwksHostsAllowlist()); | ||
assertEquals("--skey--", tokenProperties.secretKey()); | ||
} | ||
|
||
@SneakyThrows | ||
private static JwtAuthenticationProviderConfiguration parse(String yaml) { | ||
Map map = yamlConfigReader.readValue(yaml, Map.class); | ||
final JwtAuthenticationProviderConfiguration tokenProperties = | ||
yamlConfigReader.convertValue(map, JwtAuthenticationProviderConfiguration.class); | ||
return tokenProperties; | ||
} | ||
} |