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 b46c5dc
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 15 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ 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 }}

mariadb:
image: mariadb:10.7.8
ports:
Expand All @@ -25,6 +34,9 @@ jobs:
env:
DATABASE_URL: mysql+pymysql://root:ctfer@mariadb/ctfd




steps:
- name: Checkout repository
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
Expand Down Expand Up @@ -53,7 +65,7 @@ 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 }}
Expand Down
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", "/home/nicolas/Downloads/demo-deploy.zip")
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()
})

0 comments on commit b46c5dc

Please sign in to comment.