Skip to content

Commit

Permalink
WIP: ci: add e2e tests for challenge
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoFgrx committed Jun 8, 2024
1 parent 74905d2 commit e0ac6f5
Show file tree
Hide file tree
Showing 11 changed files with 534 additions and 16 deletions.
27 changes: 25 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ jobs:
PASSWORD: ctfer

services:
# chall-manager:
# image: registry.dev1.ctfer-io.lab/ctferio/chall-manager:ci
# ports:
# - 9090:9090
# - 8081:8081
# credentials:
# username: ${{ secrets.registry_user }}
# password: ${{ secrets.registry_pass }}

chall-manager:
image: nicofgrx/chall-manager:ci
ports:
- 9090:9090
- 8081:8081
credentials:
username: ${{ secrets.docker_username }}
password: ${{ secrets.docker_password }}

mariadb:
image: mariadb:10.7.8
ports:
Expand Down Expand Up @@ -53,12 +71,17 @@ jobs:
url: 'http://ctfd:8000'
appearance_name: CTFer.io
appearance_description: CTFer.io plugin tests
mode: teams
mode: users # TODO add tests with teams
admin_name: ${{ env.NAME }}
admin_email: [email protected]
admin_password: ${{ env.PASSWORD }}

- name: Generate demo-deploy.zip for tests
run: |
cd hack
zip -r ../demo-deploy.zip deploy
- name: tests with cypress
uses: cypress-io/github-action@f88a151c986cab2e339cdbede6a5c4468bb62c17 # v6.7.0
with:
env: CTFD_NAME=${{ env.NAME }},CTFD_PASSWORD=${{ env.PASSWORD }},CTFD_URL="http://localhost:8000"
env: CTFD_NAME=${{ env.NAME }},CTFD_PASSWORD=${{ env.PASSWORD }},CTFD_URL="http://localhost:8000",SCENARIO_PATH="${{ github.workspace }}/demo-deploy.zip"
12 changes: 6 additions & 6 deletions assets/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
This is how many points the challenge will cost to User to start it.
</small>
</label>
<input type="number" class="form-control" name="mana_cost" placeholder="Enter value" required>
<input type="number" data-test-id="mana-create-id" class="form-control" name="mana_cost" placeholder="Enter Mana value" required>
</div>

<div class="form-group">
Expand All @@ -37,7 +37,7 @@
</ul>
</small>
</label>
<select name="updateStrategy" class="custom-select">
<select name="updateStrategy" data-test-id="updateStrategy-create-id" class="custom-select">
<option value="update_in_place">Update in place</option>
<option value="blue_green">Blue Green</option>
<option value="recreate">Recreate</option>
Expand All @@ -47,7 +47,7 @@

<div id="cm-mode-selector" class="form-group">
<label for="select-option">Select mode </label>
<select id="select-option" name="mode">
<select id="select-option" data-test-id="mode-create-id" name="mode">
<option value="until">Until</option>
<option value="timeout" selected>Timeout</option>
</select>
Expand All @@ -59,7 +59,7 @@
This is when the Scenario has to end.
</small>
</label>
<input type="datetime-local" id="until-input-local" class="form-control">
<input type="datetime-local" id="until-input-local" data-test-id="until-create-id" class="form-control">
<input type="hidden" id="until-input-utc" class="form-control" name="until">
</div>

Expand All @@ -69,7 +69,7 @@
This is default timeout (int) <b>in seconds</b> for the Scenario to shutdown itself.
</small>
</label>
<input type="number" id="timeout-input" class="form-control" name="timeout">
<input type="number" id="timeout-input" data-test-id="timeout-create-id" class="form-control" name="timeout">
</div>

<div class="form-group">
Expand All @@ -78,7 +78,7 @@
This is the IaC Archives
</small>
</label>
<input type="file" class="form-control" id="scenario" name="scenario" accept=".zip" required>
<input type="file" class="form-control" id="scenario" data-test-id="scenario-create-id" name="scenario" accept=".zip" required>
</div>
<!-- Chall-manager specifics -->

Expand Down
8 changes: 4 additions & 4 deletions assets/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div id="whale-panel-stopped" class="card" style="width: 100%;">
<div class="card-body">
<h5 class="card-title">Instance Info</h5>
<button class="btn btn-primary card-link" style="background-color:#479abf;" id="whale-button-boot" type="button"
<button class="btn btn-primary card-link" style="background-color:#479abf;" id="whale-button-boot" type="button" data-test-id="cm-button-boot"
onclick="CTFd._internal.challenge.boot()">Launch the challenge</button>
</div>
</div>
Expand All @@ -21,17 +21,17 @@ <h6 class="card-subtitle mb-2 text-muted">
Connection Info: <code><span id="whale-challenge-lan-domain"></span></code>
</h6> -->
<p id="whale-challenge-user-access" class="card-text"></p>
<button type="button" class="btn btn-success card-link" style="background-color:#ebb850; border-color:#000000" id="whale-button-renew"
<button type="button" class="btn btn-success card-link" style="background-color:#ebb850; border-color:#000000" id="whale-button-renew" data-test-id="cm-button-renew"
onclick="CTFd._internal.challenge.renew()">
Renew
</button>

<button type="button" class="btn btn-success card-link" style="background-color:#479abf; border-color:#000000" id="whale-button-restart"
<button type="button" class="btn btn-success card-link" style="background-color:#479abf; border-color:#000000" id="whale-button-restart" data-test-id="cm-button-restart"
onclick="CTFd._internal.challenge.restart()">
Restart
</button>

<button type="button" class="btn btn-danger card-link" style="background-color:#b43c2c; border-color:#000000" id="whale-button-destroy"
<button type="button" class="btn btn-danger card-link" style="background-color:#b43c2c; border-color:#000000" id="whale-button-destroy" data-test-id="cm-button-destroy"
onclick="CTFd._internal.challenge.destroy()">
Destroy
</button>
Expand Down
8 changes: 4 additions & 4 deletions assets/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ function loadInfo() {
window.t = undefined;
}
if (response.success) response = response.data;
else CTFd._functions.events.eventAlert({
else CTFd.ui.ezq.ezAlert({
title: "Fail",
html: response.message,
body: response.data.message,
button: "OK"
});
var now = new Date();
Expand Down Expand Up @@ -138,7 +138,7 @@ CTFd._internal.challenge.destroy = function() {
} else {
CTFd.ui.ezq.ezAlert({
title: "Fail",
body: response.message,
body: response.data.message,
button: "OK"
});
reject(response.message);
Expand Down Expand Up @@ -191,7 +191,7 @@ CTFd._internal.challenge.renew = function () {
} else {
CTFd.ui.ezq.ezAlert({
title: "Fail",
body: response.message,
body: response.data.message,
button: "OK"
});
}
Expand Down
File renamed without changes.
20 changes: 20 additions & 0 deletions cypress/e2e/challenge.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
describe('Dynamic IaC Challenge', () => {

beforeEach(() => {
cy.login(Cypress.env('CTFD_NAME'), Cypress.env('CTFD_PASSWORD'))
})


it('Test all buttons for Users', () => {
let label = "tests-abcdefgh"
cy.create_challenge(label, "1", "Recreate", "timeout", "300", Cypress.env('SCENARIO_PATH'))
cy.wait(5000) // wait ctfd to create challenge and redirect to edit sections
cy.visit(`${Cypress.env("CTFD_URL")}/challenges`)
cy.get("button").contains(label).click()

// launch instance
cy.get('[data-test-id="cm-button-boot"]').click()


})
})
34 changes: 34 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,38 @@ Cypress.Commands.add('login', (username, password) => {
cy.get('#password').type(password)
cy.get('#_submit').click()
cy.url().should('contain', 'challenges')
})


Cypress.Commands.add('create_challenge', (label, mana, updateStrategy, mode, mode_value, scenario_path) => {
cy.visit(`${Cypress.env("CTFD_URL")}/admin/challenges/new`) // go on challenge creation
cy.wait(500) // wait ctfd
cy.get(".form-check-label").contains("dynamic_iac").click() // select dynamic_iac

// default attributs
cy.get("input[placeholder=\"Enter challenge name\"]").type(label)
cy.get("input[placeholder=\"Enter challenge category\"]").type(label)

// chall-manager plugins attributs
cy.get('[data-test-id="mana-create-id"]').type(mana) // set mana cost
cy.get('[data-test-id="updateStrategy-create-id"]').select(updateStrategy) // set updatestarted to Restart
cy.get('[data-test-id="mode-create-id"]').select(mode) // select timeout mode
cy.get('[data-test-id="timeout-create-id"]').type(mode_value) // define timeout seconds
cy.get('[data-test-id="scenario-create-id"]').selectFile(scenario_path) //upload file

// dynamic attributs
cy.get("input[placeholder=\"Enter value\"]").type("500")
cy.get("input[placeholder=\"Enter Decay value\"]").type("10")
cy.get("input[placeholder=\"Enter minimum value\"]").type("100")

// Create
cy.get(".create-challenge-submit").contains("Create").click()
cy.wait(7500)

// Final options
cy.get("[name=\"flag\"]").type(label)
cy.get("select[name=\"state\"]").select('Visible')

// Finish creation
cy.get(".create-challenge-submit").contains("Finish").click()
})
3 changes: 3 additions & 0 deletions hack/deploy/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: no-sdk
runtime: go
description: A challenge scenario written without the SDK, while still compliant with the chall-manager API.
92 changes: 92 additions & 0 deletions hack/deploy/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
module github.com/ctfer-io/chall-manager/examples/no-sdk/deploy

go 1.21.5

require (
github.com/pulumi/pulumi-random/sdk/v4 v4.15.1
github.com/pulumi/pulumi/sdk/v3 v3.101.0
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/charmbracelet/bubbles v0.16.1 // indirect
github.com/charmbracelet/bubbletea v0.24.2 // indirect
github.com/charmbracelet/lipgloss v0.7.1 // indirect
github.com/cheggaaa/pb v1.0.29 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/djherbis/times v1.5.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-git/go-git/v5 v5.11.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.1.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/hcl/v2 v2.17.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mitchellh/go-ps v1.0.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/opentracing/basictracer-go v1.1.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pgavlin/fx v0.1.6 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/term v1.1.0 // indirect
github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 // indirect
github.com/pulumi/esc v0.6.2 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.0.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/texttheater/golang-levenshtein v1.0.1 // indirect
github.com/tweekmonster/luser v0.0.0-20161003172636-3fa38070dbd7 // indirect
github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/zclconf/go-cty v1.13.2 // indirect
go.uber.org/atomic v1.9.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.15.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230706204954-ccb25ca9f130 // indirect
google.golang.org/grpc v1.57.1 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/frand v1.4.2 // indirect
)
Loading

0 comments on commit e0ac6f5

Please sign in to comment.