-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: cypress integration tests (#42)
* initial commit integration tests * way too many changes * fix pepr init * add cleanup command * complete cac registration and login and cleanup * final cleanup * use bundle for testing * update common * update task descriptions * no cache dev build * format typescript code * typo --------- Co-authored-by: Rob Ferguson <rjferguson21@gmail.com>
- Loading branch information
1 parent
bade26d
commit 12ea0cc
Showing
28 changed files
with
5,112 additions
and
15 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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
kind: UDSBundle | ||
metadata: | ||
name: k3d-core-slim-dev | ||
description: A UDS bundle for deploying Istio from UDS Core on a development cluster | ||
version: "dev" | ||
|
||
packages: | ||
- name: uds-k3d-dev | ||
repository: ghcr.io/defenseunicorns/packages/uds-k3d | ||
# renovate: datasource=github-tags depName=defenseunicorns/uds-k3d versioning=semver | ||
ref: 0.6.0 | ||
|
||
- name: init | ||
repository: ghcr.io/defenseunicorns/packages/init | ||
# renovate: datasource=github-tags depName=defenseunicorns/zarf versioning=semver | ||
ref: v0.32.5 | ||
|
||
- name: keycloak-identity-config | ||
path: ../ | ||
ref: dev | ||
|
||
- name: core-slim-dev | ||
path: ../uds-core/build/ | ||
# renovate: datasource=github-tags depName=defenseunicorns/uds-core versioning=semver | ||
ref: 0.18.0 | ||
overrides: | ||
keycloak: | ||
keycloak: | ||
variables: | ||
- name: KEYCLOAK_CONFIG_IMAGE | ||
description: "The keycloak config image to deploy plugin and initial setup configuration" | ||
path: configImage | ||
istio-admin-gateway: | ||
uds-istio-config: | ||
variables: | ||
- name: ADMIN_TLS_CACERT | ||
description: "The CA cert for the tenant gateway (must be base64 encoded)" | ||
path: tls.cacert | ||
istio-tenant-gateway: | ||
uds-istio-config: | ||
variables: | ||
- name: TENANT_TLS_CACERT | ||
description: "The CA cert for the tenant gateway (must be base64 encoded)" | ||
path: tls.cacert |
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,41 @@ | ||
# Integration Testing For UDS Identity Config + UDS Core | ||
|
||
[Cypress Web Flow/Integration Testing Docs](https://docs.cypress.io/guides/overview/why-cypress) | ||
|
||
## Implemented Tests | ||
|
||
| Test Name (link) | Test Description | | ||
|------------------|------------------| | ||
| [Login Existing User](../src/test/cypress/e2e/login.cy.ts) | Login in existing user that is created in the testing [realm.json](../src/test/cypress/realm.json) | | ||
| [Login Nonexistant User / Incorrect creds](../src/test/cypress/e2e/login.cy.ts) | User cannot login / authenticate with incorrect creds or without account | | ||
| [Successfuly CAC Registration](../src/test/cypress/e2e/registration.cy.ts) | New user can successfully register with CAC | | ||
| [CAC User Login](../src/test/cypress/e2e/registration.cy.ts) | New user can successfully login with CAC | | ||
| [Duplicate User Registration](../src/test/cypress/e2e/registration.cy.ts) | User cannot register more than once | | ||
| [Password check for special characters](../src/test/cypress/e2e/registration.cy.ts) | User registration requires password special characters | | ||
| [Password check for length](../src/test/cypress/e2e/registration.cy.ts) | User registration requires password length check | | ||
|
||
## Cypress Testing | ||
Using uds-cli task [`uds-core-integration-tests`](../../tasks.yaml). | ||
|
||
Task explanation: | ||
- Cleanup an existing uds-core directory ( mainly for local testing ) | ||
- Create docker image that uses the new certs as well as a testing realm.json ( has a defined user, no MFA, and no email verification ) | ||
- Clone [`uds-core`](https://github.com/defenseunicorns/uds-core) necessary for setting up k3d cluster to test against | ||
- Use that cacert in deploying `uds-core` [istio gateways](https://github.com/defenseunicorns/uds-core/tree/main/src/istio/values) | ||
- Create zarf package that combines uds-core and identity-config | ||
- Setup k3d cluster by utilizing `uds-core` (istio, keycloak, pepr, zarf) | ||
- Deploy zarf package that was created earlier | ||
- Run cypress tests against deployed cluster | ||
|
||
## Updating Cypress Certs | ||
|
||
Cypress testing requires that a ca.cer be created and put into an authorized_certs.zip, done by using the `regenerate-test-pki` uds task, which is then utilized by the [Dockerfile](../src/Dockerfile). Once a docker image has been created another command is used for pulling that cacert, uds task `cacert`, from the image using it's value to configure uds-core's gateways, `uds-core-gateway-cacert` uds task . Eventually cypress will require a [pfx cert](../src/test/cypress/cypress.config.ts) for its CAC testing. | ||
|
||
Our cypress testing utilizes [static certs](../src/test/cypress/certs/) that are created and saved to limit the need for constantly rebuilding and importing those certs. | ||
|
||
Follow these steps to update the certs for cypress: | ||
1. Run `uds run regenerate-test-pki` to regenerate the necessary certs and authorized_certs.zip | ||
2. Run `docker build --build-arg CA_ZIP_URL="authorized_certs.zip" -t uds-core-config:keycloak --no-cache src` to create docker image | ||
3. Run `uds run cacert` to extract cacert from docker image for the tls_cacert.yaml file | ||
4. Copy the authorized_certs.zip, test.pfx, and tls_cacert.yaml into the [certs directory](../src/test/cypress/certs/) | ||
- `mv test.pfx tls_cacert.yaml src/authorized_certs.zip src/cypress/certs/` |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[req] | ||
default_bits = 2048 | ||
distinguished_name = req_distinguished_name | ||
req_extensions = req_ext | ||
x509_extensions = v3_ext | ||
|
||
[req_distinguished_name] | ||
countryName = Country Name (2 letter code) | ||
countryName_default = US | ||
stateOrProvinceName = State or Province Name (full name) | ||
stateOrProvinceName_default = Colorado | ||
localityName = Locality Name (eg, city) | ||
localityName_default = Colorado Springs | ||
organizationName = Organization Name (eg, company) | ||
organizationName_default = Defense Unicorns | ||
commonName = Common Name (e.g. server FQDN or YOUR name) | ||
commonName_default = uds.dev | ||
|
||
[req_ext] | ||
subjectAltName = @alt_names | ||
|
||
[v3_ext] | ||
subjectAltName = @v3_alt_names | ||
subjectKeyIdentifier = hash | ||
authorityKeyIdentifier = keyid,issuer | ||
keyUsage = digitalSignature | ||
extendedKeyUsage = clientAuth, 2.16.840.1.101.3.6.8 | ||
certificatePolicies = @policy_anything | ||
|
||
[alt_names] | ||
DNS.0 = *.uds.dev | ||
|
||
[v3_alt_names] | ||
otherName.0 = 2.16.840.1.101.3.6.6;UTF8:test@mil | ||
|
||
[policy_anything] | ||
policyIdentifier = 2.16.840.1.101.3.2.1.3.12 |
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,2 @@ | ||
node_modules | ||
cypress |
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,13 @@ | ||
{ | ||
"arrowParens": "avoid", | ||
"bracketSameLine": true, | ||
"bracketSpacing": true, | ||
"embeddedLanguageFormatting": "auto", | ||
"insertPragma": false, | ||
"printWidth": 100, | ||
"quoteProps": "as-needed", | ||
"requirePragma": false, | ||
"semi": true, | ||
"useTabs": false, | ||
"tabWidth": 2 | ||
} |
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,3 @@ | ||
# Integration Testing For UDS Identity Config + UDS Core | ||
|
||
See [docs](../../../docs/INTEGRATION.md) |
Binary file not shown.
Empty file.
Binary file not shown.
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,2 @@ | ||
tls: | ||
cacert: "Ci0tLS0tQkVHSU4gQ0VSVElGSUNBVEUtLS0tLQpNSUlEcVRDQ0FwR2dBd0lCQWdJVUE0WlU1ZWVQaGkxQWFLcEZybXAvcjUzV3VtQXdEUVlKS29aSWh2Y05BUUVMCkJRQXdaREVMTUFrR0ExVUVCaE1DVlZNeEdEQVdCZ05WQkFvTUQxVXVVeTRnUjI5MlpYSnViV1Z1ZERFTU1Bb0cKQTFVRUN3d0RSRzlFTVF3d0NnWURWUVFMREFOUVMwa3hIekFkQmdOVkJBTU1Ga1JQUkNCSlJDQkRRUzAxT1NCRwpRVXRGSUZSRlUxUXdIaGNOTWpRd05EQTBNVFF6TXpNMFdoY05Namt3TkRBek1UUXpNek0wV2pCa01Rc3dDUVlEClZRUUdFd0pWVXpFWU1CWUdBMVVFQ2d3UFZTNVRMaUJIYjNabGNtNXRaVzUwTVF3d0NnWURWUVFMREFORWIwUXgKRERBS0JnTlZCQXNNQTFCTFNURWZNQjBHQTFVRUF3d1dSRTlFSUVsRUlFTkJMVFU1SUVaQlMwVWdWRVZUVkRDQwpBU0l3RFFZSktvWklodmNOQVFFQkJRQURnZ0VQQURDQ0FRb0NnZ0VCQUtkejk3dUovZ3RmVDRWbXFzMmZRUDRnCmVtd2lkQjJBd01iQ1ZaYzZMTEhCUi9oWG96Mk8xYTFGT3NwMlhPWldWT1llQTM1WVlMZVpOYjI1OEQ1eXBLdnYKVTI0V2xkWUZId1J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ode 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,30 @@ | ||
import { defineConfig } from "cypress"; | ||
|
||
module.exports = defineConfig({ | ||
clientCertificates: [ | ||
{ | ||
url: "https://sso.uds.dev/**", | ||
ca: [], | ||
certs: [ | ||
{ | ||
pfx: "certs/test.pfx", | ||
passphrase: "certs/pfx_passphrase.txt", | ||
}, | ||
], | ||
}, | ||
], | ||
|
||
e2e: { | ||
setupNodeEvents(on, config) { | ||
// implement node event listeners here | ||
}, | ||
retries: 3, | ||
specPattern: "e2e/**/*.cy.ts", | ||
supportFolder: "support/", | ||
supportFile: "support/e2e.ts", | ||
screenshotOnRunFailure: false, | ||
video: false, | ||
}, | ||
|
||
pageLoadTimeout: 12000, | ||
}); |
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 @@ | ||
import { RegistrationFormData } from "../support/types"; | ||
|
||
describe("Login Flow", () => { | ||
it("Existing User", () => { | ||
// existing user created in test realm.json | ||
const formData: RegistrationFormData = { | ||
firstName: "Testing", | ||
lastName: "User", | ||
username: "testing_user", | ||
password: "testingpassword!!", | ||
}; | ||
|
||
cy.loginUser(formData.username, formData.password); | ||
|
||
// skip the DoD PKI Detected Pop Up | ||
cy.get("input#kc-cancel.btn.btn-light").click(); | ||
|
||
// Verify Successful Registration and on User Account Page | ||
cy.get("#landingLoggedInUser") | ||
.should("be.visible") | ||
.and("contain", formData.firstName + " " + formData.lastName); | ||
}); | ||
|
||
it("Invalid User Creds", () => { | ||
const formData: RegistrationFormData = { | ||
username: "testing_user", | ||
password: "PrettyUnicorns!!", | ||
}; | ||
|
||
cy.loginUser(formData.username, formData.password); | ||
|
||
// user doesn't exist or password is incorrect | ||
cy.contains("span", "Invalid username or password.").should("be.visible"); | ||
}); | ||
}); |
Oops, something went wrong.