Skip to content

Commit 9908b97

Browse files
authored
Merge pull request #9 from curityio/feature/add-functional-tests
Add Cypress tests and GitHub Action workflow
2 parents 528e97f + c811bca commit 9908b97

File tree

13 files changed

+5408
-0
lines changed

13 files changed

+5408
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: end-to-end-github-authenticator-tests
2+
on: workflow_dispatch
3+
jobs:
4+
run-test:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: Checkout repository
8+
uses: actions/checkout@v3
9+
- name: Checkout the utils repository
10+
uses: actions/checkout@v3
11+
with:
12+
repository: curityio/github-actions-utilities
13+
path: utils
14+
- name: Setup Java with maven cache
15+
if: ${{ !env.ACT }} # Run only in GitHub
16+
uses: actions/setup-java@v3
17+
with:
18+
distribution: 'temurin'
19+
java-version: '17'
20+
cache: maven
21+
22+
- name: Build plugin
23+
run: mvn package
24+
25+
- name: Move plugin jar to volume dir
26+
run: mv target/*.jar plugin/
27+
28+
- name: Start the Curity Identity Server
29+
env:
30+
TEST_LICENSE: ${{ secrets.idsvr_license }}
31+
GITHUB_CLIENT_ID: ${{ secrets.github_client_id }}
32+
GITHUB_CLIENT_SECRET: ${{ secrets.github_client_secret }}
33+
run: docker run -d --rm -e PASSWORD=Password1 -e GITHUB_CLIENT_ID=$GITHUB_CLIENT_ID -e GITHUB_CLIENT_SECRET=$GITHUB_CLIENT_SECRET -e TEST_LICENSE=$TEST_LICENSE -v $GITHUB_WORKSPACE/plugin:/opt/idsvr/usr/share/plugins/github-authenticator -v $GITHUB_WORKSPACE/tests/idsvr/config.xml:/opt/idsvr/etc/init/config.xml -p 6749:6749 -p 8443:8443 curity.azurecr.io/curity/idsvr:latest
34+
35+
- name: Wait for the Curity Identity Server
36+
run: ./utils/scripts/healthCheckIdsvr.sh
37+
env:
38+
ADMIN_USER: admin
39+
ADMIN_PASSWORD: Password1
40+
WAIT_TIMEOUT: 60
41+
42+
- name: Run Cypress tests
43+
uses: cypress-io/github-action@v2
44+
with:
45+
working-directory: tests

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ target/
33
.idea/
44
*.iml
55
.DS_store
6+
7+
.secrets
8+
utils/
9+
10+
tests/node_modules
11+
tests/cypress/reports

README.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,29 @@ Once all of these changes are made, they will be staged, but not committed (i.e.
117117

118118
Once the configuration is committed and running, the authenticator can be used like any other.
119119

120+
Tests
121+
~~~~~
122+
123+
The plugin is tested using end to end tests that run on a GitHub Actions workflow. The test starts up an instance of the
124+
Curity Identity Server, a simple SPA and uses Cypress to perform a login flow.
125+
126+
Running tests Locally with Cypress
127+
""""""""""""""""""""""""""""""""""
128+
129+
To run the test suite locally, first ensure that you have an instance of the Curity Identity Server running with the plugin
130+
installed and using the configuration found in `tests/idsvr/config.xml`. Next install Cypress using the following commands. ::
131+
132+
cd tests
133+
npm i
134+
135+
You can then open the Cypress app to run tests with ``npm run cypress.open`` or run the headless version of the tests with
136+
``npm run cypress.run``.
137+
138+
Running the GitHub Actions Workflow Locally
139+
"""""""""""""""""""""""""""""""""""""""""""
140+
141+
To run the GitHub Actions workflow locally refer to this `README <https://github.com/curityio/github-action-utilities>`.
142+
120143
License
121144
~~~~~~~
122145

plugin/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.jar

tests/cypress.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"chromeWebSecurity": false,
3+
"viewportWidth": 1920,
4+
"viewportHeight": 1080,
5+
"defaultCommandTimeout": 10000,
6+
"videosFolder": "cypress/reports/videos",
7+
"screenshotsFolder": "cypress/reports/screenshots",
8+
"videoUploadOnPasses": false,
9+
"retries": 1,
10+
"testFiles": [
11+
"**/*.spec.js"
12+
],
13+
"reporter": "mochawesome",
14+
"reporterOptions": {
15+
"reportDir": "cypress/reports/separate-reports",
16+
"overwrite": false,
17+
"html": false,
18+
"json": true
19+
}
20+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2022 Curity AB
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
describe('GitHub Authenticator tests', () => {
18+
it('Verify that GitHub Authenticator properly initializes authorization request', () => {
19+
20+
const authorizationURL = new URL('https://localhost:8443/oauth/v2/oauth-authorize')
21+
const params = authorizationURL.searchParams
22+
23+
params.append('client_id', 'oauth-assistant-client')
24+
params.append('response_type', 'code')
25+
params.append('redirect_uri', 'http://localhost:8080/')
26+
params.append('prompt', 'login')
27+
28+
cy.visit(authorizationURL.toString());
29+
30+
// Verify that GitHub has returned a login form
31+
cy.get('#login_field')
32+
.should('exist');
33+
})
34+
35+
})

tests/cypress/plugins/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************************
3+
// This example plugins/index.js can be used to load plugins
4+
//
5+
// You can change the location of this file or turn off loading
6+
// the plugins file with the 'pluginsFile' configuration option.
7+
//
8+
// You can read more here:
9+
// https://on.cypress.io/plugins-guide
10+
// ***********************************************************
11+
12+
// This function is called when a project is opened or re-opened (e.g. due to
13+
// the project's config changing)
14+
15+
/**
16+
* @type {Cypress.PluginConfig}
17+
*/
18+
// eslint-disable-next-line no-unused-vars
19+
module.exports = (on, config) => {
20+
// `on` is used to hook into various events Cypress emits
21+
// `config` is the resolved Cypress config
22+
}

tests/cypress/support/commands.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// ***********************************************
2+
// This example commands.js shows you how to
3+
// create various custom commands and overwrite
4+
// existing commands.
5+
//
6+
// For more comprehensive examples of custom
7+
// commands please read more here:
8+
// https://on.cypress.io/custom-commands
9+
// ***********************************************
10+
//
11+
//
12+
// -- This is a parent command --
13+
// Cypress.Commands.add('login', (email, password) => { ... })
14+
//
15+
//
16+
// -- This is a child command --
17+
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
18+
//
19+
//
20+
// -- This is a dual command --
21+
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
22+
//
23+
//
24+
// -- This will overwrite an existing command --
25+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })

tests/cypress/support/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ***********************************************************
2+
// This example support/index.js is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands'
18+
19+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')

0 commit comments

Comments
 (0)