-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remore Code Refactor in RotatingClientKeyProvider
- Loading branch information
Showing
3 changed files
with
67 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
35 changes: 35 additions & 0 deletions
35
src/test/java/com/uid2/shared/auth/RotatingClientKeyProviderTest.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,35 @@ | ||
package com.uid2.shared.auth; | ||
|
||
import com.uid2.shared.cloud.EmbeddedResourceStorage; | ||
import com.uid2.shared.store.CloudPath; | ||
import com.uid2.shared.store.reader.RotatingClientKeyProvider; | ||
import com.uid2.shared.store.scope.GlobalScope; | ||
import io.vertx.core.json.JsonObject; | ||
import org.junit.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.Assert.*; | ||
|
||
public class RotatingClientKeyProviderTest { | ||
@Test | ||
public void testGetOldestClientKeyBySiteId() throws Exception { | ||
RotatingClientKeyProvider provider = new RotatingClientKeyProvider( | ||
new EmbeddedResourceStorage(RotatingClientKeyProviderTest.class), | ||
new GlobalScope(new CloudPath("/com.uid2.shared/test/clients/metadata.json"))); | ||
|
||
JsonObject metadata = provider.getMetadata(); | ||
provider.loadContent(metadata); | ||
assertEquals(1, provider.getVersion(metadata)); | ||
|
||
// a site that has multiple client keys | ||
ClientKey expected = provider.getClientKey("trusted-partner-key"); | ||
assertNotNull(expected); | ||
ClientKey actual = provider.getOldestClientKey(expected.getSiteId()); | ||
assertNotNull(actual); | ||
assertThat(actual).isEqualTo(expected); | ||
|
||
// a site that doesn't have client keys | ||
actual = provider.getOldestClientKey(1234567890); | ||
assertNull(actual); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -42,5 +42,27 @@ | |
"created": 1617149276, | ||
"roles": [ "ID_READER", "MAPPER", "GENERATOR" ], | ||
"site_id": 6 | ||
}, | ||
{ | ||
"key": "trusted-partner-key-latest1", | ||
"key_hash": "JgdHSbec8S5qhVQeCwy0FVEwYknBVtccxccHHUobRFYVvzTmj0i2EQMhZ6BCBzSpI7I3Vd1RxMd3P2IOLGt+tA==", | ||
"key_salt": "RSn7ZU+fjFtku6zDKJ1cpmeWqqxihF1FmrPRv4+78+M=", | ||
"secret": "wJ0hP19QU4hmpB64Y3fV2dAed8t/mupw3sjN5jNRFzg=", | ||
"name": "[email protected]", | ||
"contact": "[email protected]", | ||
"created": 1654596485, | ||
"roles": [ "ID_READER", "MAPPER", "GENERATOR" ], | ||
"site_id": 6 | ||
}, | ||
{ | ||
"key": "trusted-partner-key-latest2", | ||
"key_hash": "JgdHSbec8S6qhVQeCwy0FVEwYknBVtccxccHHUobRFYVvzTmj0i2EQMhZ6BCBzSpI7I3Vd1RxMd3P2IOLGt+tA==", | ||
"key_salt": "RSn7ZU+fjFtku6zDKJ1cpmeWqqxihF1FmrPRv4+78+M=", | ||
"secret": "wJ0hP19QU4hmpB64Y3fV2dAed8t/mupw3sjN5jNRFzg=", | ||
"name": "[email protected]", | ||
"contact": "[email protected]", | ||
"created": 1694596485, | ||
"roles": [ "ID_READER", "MAPPER", "GENERATOR" ], | ||
"site_id": 6 | ||
} | ||
] |