-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding the ability to diable CSTG key #559
Merged
cody-constine-ttd
merged 3 commits into
main
from
cbc-UID2-2987-ensure-disabling-cstg-works
May 21, 2024
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -42,7 +42,6 @@ | |
import io.vertx.ext.web.client.WebClient; | ||
import io.vertx.junit5.VertxExtension; | ||
import io.vertx.junit5.VertxTestContext; | ||
import org.apache.commons.collections4.CollectionUtils; | ||
import org.junit.jupiter.api.*; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
|
@@ -3094,6 +3093,55 @@ void cstgLogsInvalidAppName(String appName, Vertx vertx, VertxTestContext testCo | |
}); | ||
} | ||
|
||
@Test | ||
void catalogsDisabledAsUnauthorized(Vertx vertx, VertxTestContext testContext) throws NoSuchAlgorithmException, InvalidKeyException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can it be prefixed with "cstg" to make the tests easier to search and group? |
||
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"); | ||
thomasm-ttd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
final PublicKey serverPublicKey = ClientSideTokenGenerateTestUtil.stringToPublicKey(clientSideTokenGeneratePublicKey, kf); | ||
final PrivateKey clientPrivateKey = ClientSideTokenGenerateTestUtil.stringToPrivateKey("MEECAQAwEwYHKoZIzj0CAQYIKoZIzj0DAQcEJzAlAgEBBCDsqxZicsGytVqN2HZqNDHtV422Lxio8m1vlflq4Jb47Q==", kf); | ||
final SecretKey secretKey = ClientSideTokenGenerateTestUtil.deriveKey(serverPublicKey, clientPrivateKey); | ||
|
||
final byte[] iv = Random.getBytes(12); | ||
final long timestamp = Instant.now().toEpochMilli(); | ||
final JsonArray aad = JsonArray.of(timestamp); | ||
String rawId = "[email protected]"; | ||
|
||
JsonObject identityPayload = new JsonObject(); | ||
identityPayload.put("email_hash", getSha256(rawId)); | ||
byte[] payloadBytes = ClientSideTokenGenerateTestUtil.encrypt(identityPayload.toString().getBytes(), secretKey.getEncoded(), iv, aad.toBuffer().getBytes()); | ||
final String payload = EncodingUtils.toBase64String(payloadBytes); | ||
|
||
JsonObject requestJson = new JsonObject(); | ||
requestJson.put("payload", payload); | ||
requestJson.put("iv", EncodingUtils.toBase64String(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")); | ||
testContext.completeNow(); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can also assertTokenStatusMetrics here |
||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"true,http://gototest.com", | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The others are PascalCase