-
Notifications
You must be signed in to change notification settings - Fork 8
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
AUT-3916: Adding integration tests for MFA Reset #5693
Open
andrew-moores
wants to merge
16
commits into
main
Choose a base branch
from
aut-3916
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ead1354
AUT-3691: Use finalizedBy to complete test cleanly
andrew-moores 7a25fe3
AUT-3691: Remove superfluous configuration of jacoco from the integra…
andrew-moores f3efdf6
AUT-3691: Remove test filter from delivery-receipts-integration-tests…
andrew-moores d6fe948
AUT-3691: Added a testLogging configuration to the test task in di-au…
andrew-moores 6109f84
AUT-3691: Removed filter from test task to make it consistent with th…
andrew-moores c316ddc
AUT-3691: Add test to check the JWKS endpoint serves the public key u…
andrew-moores 3155769
AUT-3691: Add test to check the Storage Token JWKS endpoint serves th…
andrew-moores 4c3af37
AUT-3691: Add tests to check the JWKS lambdas don't allow exceptions …
andrew-moores 0d3978d
AUT-3691: Use the Junit extension for creating KMS keys with the modi…
andrew-moores a39fb86
AUT-3691: Improve logging to make it clear when keys have been succes…
andrew-moores 8a5f704
AUT-3691: Add integration test for MFAResetAuthorizeHandler.
andrew-moores 9504232
AUT-3691: Add integration test for ReverificationResultHandler and up…
andrew-moores 871aa78
AUT-3691: Update MfaResetAuthorizeHandlerIntegrationTest to create th…
andrew-moores 0d90ca0
AUT-3691: Update MfaResetAuthorizeHandlerIntegrationTest to fix the i…
andrew-moores 6fb67be
AUT-3916: Corrections to tests following rebase.
andrew-moores dd04adf
AUT-3916: Clarification to key id provided in JWKS
andrew-moores 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
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
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
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
124 changes: 124 additions & 0 deletions
124
...n-tests/src/test/java/uk/gov/di/authentication/api/AuthSigningKeyJWKSIntegrationTest.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,124 @@ | ||
package uk.gov.di.authentication.api; | ||
|
||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParser; | ||
import com.nimbusds.jose.JWSAlgorithm; | ||
import com.nimbusds.jose.jwk.Curve; | ||
import com.nimbusds.jose.jwk.KeyType; | ||
import com.nimbusds.jose.jwk.KeyUse; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; | ||
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; | ||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.services.kms.KmsClient; | ||
import software.amazon.awssdk.services.kms.model.GetPublicKeyRequest; | ||
import software.amazon.awssdk.services.kms.model.GetPublicKeyResponse; | ||
import software.amazon.awssdk.services.kms.model.KeyUsageType; | ||
import uk.gov.di.authentication.frontendapi.lambda.MfaResetJarJwkHandler; | ||
import uk.gov.di.authentication.shared.services.ConfigurationService; | ||
import uk.gov.di.authentication.sharedtest.basetest.ApiGatewayHandlerIntegrationTest; | ||
import uk.gov.di.authentication.sharedtest.extensions.KmsKeyExtension; | ||
import uk.gov.di.authentication.sharedtest.logging.CaptureLoggingExtension; | ||
import uk.org.webcompere.systemstubs.environment.EnvironmentVariables; | ||
import uk.org.webcompere.systemstubs.jupiter.SystemStub; | ||
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension; | ||
|
||
import java.net.URI; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.hasItem; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static uk.gov.di.authentication.shared.helpers.HashHelper.hashSha256String; | ||
import static uk.gov.di.authentication.sharedtest.logging.LogEventMatcher.withMessageContaining; | ||
import static uk.gov.di.orchestration.sharedtest.matchers.APIGatewayProxyResponseEventMatcher.hasStatus; | ||
|
||
@ExtendWith(SystemStubsExtension.class) | ||
class AuthSigningKeyJWKSIntegrationTest extends ApiGatewayHandlerIntegrationTest { | ||
private static final Logger LOG = LogManager.getLogger(AuthSigningKeyJWKSIntegrationTest.class); | ||
|
||
@SystemStub private static final EnvironmentVariables environment = new EnvironmentVariables(); | ||
|
||
@RegisterExtension | ||
private static final KmsKeyExtension mfaResetJarSigningKey = | ||
new KmsKeyExtension("mfa-reset-jar-signing-key", KeyUsageType.SIGN_VERIFY); | ||
|
||
@RegisterExtension | ||
private static final CaptureLoggingExtension logging = | ||
new CaptureLoggingExtension(MfaResetJarJwkHandler.class); | ||
|
||
private static String expectedHashKeyArn; | ||
|
||
@BeforeAll | ||
static void setupEnvironment() { | ||
environment.set( | ||
"IPV_REVERIFICATION_REQUESTS_SIGNING_KEY_ALIAS", mfaResetJarSigningKey.getKeyId()); | ||
|
||
try (KmsClient kmsClient = getKmsClient()) { | ||
GetPublicKeyRequest getPublicKeyRequest = | ||
GetPublicKeyRequest.builder().keyId(mfaResetJarSigningKey.getKeyId()).build(); | ||
|
||
GetPublicKeyResponse getPublicKeyResponse = kmsClient.getPublicKey(getPublicKeyRequest); | ||
|
||
expectedHashKeyArn = hashSha256String(getPublicKeyResponse.keyId()); | ||
} catch (Exception e) { | ||
LOG.error(e.getMessage(), e); | ||
} | ||
} | ||
|
||
private static KmsClient getKmsClient() { | ||
return KmsClient.builder() | ||
.endpointOverride(URI.create("http://localhost:45678")) | ||
.credentialsProvider( | ||
StaticCredentialsProvider.create( | ||
AwsBasicCredentials.create("dummy", "dummy"))) | ||
.region(Region.EU_WEST_2) | ||
.build(); | ||
} | ||
|
||
@Test | ||
void shouldReturnJWKSetContainingTheReverificationSigningKey() { | ||
handler = new MfaResetJarJwkHandler(new ConfigurationService()); | ||
|
||
var response = makeRequest(Optional.empty(), Map.of(), Map.of()); | ||
|
||
assertThat(response, hasStatus(200)); | ||
|
||
JsonObject jwk = JsonParser.parseString(response.getBody()).getAsJsonObject(); | ||
JsonArray keys = jwk.get("keys").getAsJsonArray(); | ||
assertEquals(1, keys.size(), "JWKS endpoint must return a single key."); | ||
|
||
checkPublicSigningKeyResponseMeetsADR0030(keys.get(0).getAsJsonObject()); | ||
} | ||
|
||
@Test | ||
void shouldNotAllowExceptionsToEscape() { | ||
environment.set("IPV_REVERIFICATION_REQUESTS_SIGNING_KEY_ALIAS", "wrong-key-alias"); | ||
|
||
handler = new MfaResetJarJwkHandler(new ConfigurationService()); | ||
|
||
var response = makeRequest(Optional.empty(), Map.of(), Map.of()); | ||
|
||
assertThat(response, hasStatus(500)); | ||
assertThat( | ||
logging.events(), | ||
hasItem( | ||
withMessageContaining( | ||
"Failed to serve Auth reverification request JAR signature verification key."))); | ||
} | ||
|
||
private static void checkPublicSigningKeyResponseMeetsADR0030(JsonObject key) { | ||
assertEquals(expectedHashKeyArn, key.get("kid").getAsString()); | ||
assertEquals(KeyType.EC.getValue(), key.get("kty").getAsString()); | ||
assertEquals(KeyUse.SIGNATURE.getValue(), key.get("use").getAsString()); | ||
assertEquals(Curve.P_256.getName(), key.get("crv").getAsString()); | ||
assertEquals(JWSAlgorithm.ES256.toString(), key.get("alg").getAsString()); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
In the commit message here can we add the detail of what the issue was here and why we think this fixes? Just to have the context there for future (you explained it to me and I've already forgotten :-D)