-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #559 from IABTechLab/cbc-UID2-2987-ensure-disablin…
…g-cstg-works Adding the ability to diable CSTG key
- Loading branch information
Showing
3 changed files
with
53 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3194,6 +3194,51 @@ void cstgLogsInvalidAppName(String appName, Vertx vertx, VertxTestContext testCo | |
}); | ||
} | ||
|
||
@Test | ||
void cstgDisabledAsUnauthorized(Vertx vertx, VertxTestContext testContext) throws NoSuchAlgorithmException, InvalidKeyException { | ||
ListAppender<ILoggingEvent> logWatcher = new ListAppender<>(); | ||
logWatcher.start(); | ||
((Logger) LoggerFactory.getLogger(UIDOperatorVerticle.class)).addAppender(logWatcher); | ||
this.uidOperatorVerticle.setLastInvalidOriginProcessTime(Instant.now().minusSeconds(3600)); | ||
|
||
setupCstgBackend(); | ||
String subscriptionID = "PpRrE5YY84"; | ||
ClientSideKeypair keypairDisabled = new ClientSideKeypair(subscriptionID, clientSideTokenGeneratePublicKey, clientSideTokenGeneratePrivateKey, clientSideTokenGenerateSiteId, "", Instant.now(), true, ""); | ||
when(clientSideKeypairProvider.getSnapshot()).thenReturn(clientSideKeypairSnapshot); | ||
when(clientSideKeypairSnapshot.getKeypair(subscriptionID)).thenReturn(keypairDisabled); | ||
|
||
final KeyFactory kf = KeyFactory.getInstance("EC"); | ||
final PublicKey serverPublicKey = ClientSideTokenGenerateTestUtil.stringToPublicKey(clientSideTokenGeneratePublicKey, kf); | ||
final PrivateKey clientPrivateKey = ClientSideTokenGenerateTestUtil.stringToPrivateKey("MEECAQAwEwYHKoZIzj0CAQYIKoZIzj0DAQcEJzAlAgEBBCDsqxZicsGytVqN2HZqNDHtV422Lxio8m1vlflq4Jb47Q==", kf); | ||
final SecretKey secretKey = ClientSideTokenGenerateTestUtil.deriveKey(serverPublicKey, clientPrivateKey); | ||
final long timestamp = Instant.now().toEpochMilli(); | ||
|
||
|
||
JsonObject requestJson = new JsonObject(); | ||
requestJson.put("payload", ""); | ||
requestJson.put("iv", ""); | ||
requestJson.put("public_key", serverPublicKey.toString()); | ||
requestJson.put("timestamp", timestamp); | ||
requestJson.put("subscription_id", subscriptionID); | ||
|
||
Tuple.Tuple2<JsonObject, SecretKey> data = createClientSideTokenGenerateRequest(IdentityType.Email, "[email protected]", Instant.now().toEpochMilli(), false, null); | ||
sendCstg(vertx, | ||
"v2/token/client-generate", | ||
null, | ||
requestJson, | ||
secretKey, | ||
401, | ||
testContext, | ||
respJson -> { | ||
assertEquals("Unauthorized", respJson.getString("message")); | ||
assertTokenStatusMetrics( | ||
clientSideTokenGenerateSiteId, | ||
TokenResponseStatsCollector.Endpoint.ClientSideTokenGenerateV2, | ||
TokenResponseStatsCollector.ResponseStatus.Unauthorized); | ||
testContext.completeNow(); | ||
}); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"true,http://gototest.com", | ||
|