Skip to content
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

Introduce separate configuration for challenges #1083

Merged
merged 28 commits into from
Dec 6, 2023

Conversation

nbaars
Copy link
Collaborator

@nbaars nbaars commented Nov 17, 2023

This PR split the configuration of a challenge into two parts:

  • Challenge definition
  • Challenge (the actual code)

Each definition can link to 1 or more challenges. This makes it possible to have different implementations and documentation for each environment. For example:

   - name: Challenge 5
      url: "challenge-5"
      sources:
        - class-name: "org.owasp.wrongsecrets.challenges.kubernetes.Challenge5"
          explanation: "explanations/challenge5.adoc"
          hint: "explanations/challenge5_hint.adoc"
          reason: "explanations/challenge5_reason.adoc"
          environments: [ *k8s, *k8s_vault ]
        - class-name: "org.owasp.wrongsecrets.challenges.kubernetes.Challenge5"
          explanation: "explanations/challenge5.adoc"
          hint: "explanations/challenge5_hint_limited.adoc"
          reason: "explanations/challenge5_reason.adoc"
          environments: [ *okteto ]
      difficulty: *normal
      category: *config_maps
      ctf:
        enabled: true

This example shows how we can define for different environments different hints. This also makes it possible to have a different Challenge class per environment.

The configuration for the application is also part of the yaml configuration. For example, the environments, difficulty levels are now defined in the yaml file:

  difficulties:
    - &easy "easy"
    - &normal "normal"
    - &hard "hard"
    - &expert "expert"
    - &master "master"

Adding a new difficulty level is as easy as adding a new entry in this yaml section. No code changes are necessary to add a new difficulty level. Same applies for categories and environments it only needs a config update.

The UI now treats every challenge the same. No more specific "challenge" code leaks into the main part of the application.

The order of the challenges is now defined by the configuration file, if you want to change the order you can simply change the order in the yaml file. Also if you want to run WrongSecrets with a couple of challenges only need to change the yaml file.

** Performance **

Starting time locally is now:

o.o.w.WrongSecretsApplication            : Started WrongSecretsApplication in 1.978 seconds (process running for 2.312)

The memory consumption is around 90 Mb

image

Closes #502

@nbaars nbaars force-pushed the nbaars/config-challenges branch from 645f0c9 to 04ee7c2 Compare November 17, 2023 13:07
pom.xml Show resolved Hide resolved
.github/scripts/.bash_history Outdated Show resolved Hide resolved
@nbaars nbaars force-pushed the nbaars/config-challenges branch from ceb5b58 to 3ca0af1 Compare November 17, 2023 19:31
Copy link
Collaborator

@commjoen commjoen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review in progress, first looks: pretty good! Thank you @nbaars !

@commjoen
Copy link
Collaborator

Spotbugs spits out a few errors at https://github.com/OWASP/wrongsecrets/actions/runs/6909060649/job/18799652205?pr=1083: can you please have a look good sir?

pom.xml Show resolved Hide resolved
.github/scripts/.bash_history Outdated Show resolved Hide resolved
.github/workflows/link_checker.yml Show resolved Hide resolved
.github/workflows/minikube-k8s-test.yml Show resolved Hide resolved
CONTRIBUTING.md Show resolved Hide resolved
}

@Override
public int getTotalReceivedPoints() {
return solvedChallenges.stream()
.map(challenge -> challenge.difficulty() * (100 + (challenge.difficulty() - 1) * 25))
.map(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we maybe just cache this value? it's just an int right?

@RemakingEden
Copy link
Collaborator

RemakingEden commented Nov 20, 2023

So Ive just been running the tests locally.

Positives

  • They are so much neater and less hacky in the new place
  • After a really long set up they run really quickly each time after

Negatives/questions

  • It is a little hard to tell what has failed.
    image
  • How does a user get to the visual debugger?
  • Is it possible to still upload screenshots and videos?

@@ -48,15 +48,6 @@ jobs:
with:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this whole ui-test section need removing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is now part of the normal tests. You can run it as a normal unit-test with different Spring Boot configurations per Cypress test if necessary

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests are still there they are now part of the normal tests

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah sorry, I was saying that so far you have just deleted a step in the ui-test section. I think the whole "ui-test:" object needs removing

Nanne Baars and others added 7 commits November 20, 2023 21:05
A challenge has a name and a short name, which can be used in URLs etc. Using `shortName` instead of `url` makes more sense.
Next on last challenge should be disabled.
Link now points to the right URL and added a Cypress test to verify clicking the link.
Since we only need the contents in the CTF controller we can make this a bit more lazy.
@nbaars
Copy link
Collaborator Author

nbaars commented Nov 21, 2023

So Ive just been running the tests locally.

Positives

  • They are so much neater and less hacky in the new place
  • After a really long set up they run really quickly each time after

Negatives/questions

  • It is a little hard to tell what has failed.
    image
  • How does a user get to the visual debugger?

The screenshots are saved, you can also run the Cypress test directly from Intellij.

  • Is it possible to still upload screenshots and videos?
    The screenshots are still saved in src/test/e2e/cypress/screenshots. For example:
    image

@commjoen
Copy link
Collaborator

Re #1083 (comment): can we maybe have the "howto" added to the contributing.md ;) ?

@RemakingEden
Copy link
Collaborator

Re #1083 (comment): can we maybe have the "howto" added to the contributing.md ;) ?

Yeah I think something to explain this to new users and we will be away! Apart from those answered concerns I think everything is an improvement. It feels loads cleaner!!

@commjoen
Copy link
Collaborator

@nbaars can you please have a look at the remaining issues at https://github.com/OWASP/wrongsecrets/actions/runs/6948950794/job/18906041764?pr=1083 so we can merge and fix more bugs in separate PRs?

@commjoen
Copy link
Collaborator

commjoen commented Dec 5, 2023

Created #1105 for future improvements once this is merged

{
"reporterEnabled": "spec, mochawesome",
"mochawesomeReporterOptions": {
"reportDir": "cypress/reports/mochawesome",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't seem to be getting this mochawsome report when I run the tests. Should a report appear this in this path after each run?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weirdly I am also still not seeing screenshots on a failure

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
This is my path after a failure

@@ -4,14 +4,15 @@ This project uses [Cypress](https://www.cypress.io/) to run UI tests for the pro

## How to run the tests
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a new section in here about how to use the visual debugger is important. Unless this is possible with maven. So we have one method of using it quickly and easily through unit tests and one way that is a little harder to run but way easier to debug visually. If youd like im happy to add this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add this to #1105 please :-)?

Copy link
Collaborator

@bendehaan bendehaan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great improvements here, thanks a lot! 😁

Copy link
Collaborator

@commjoen commjoen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @nbaars for another big step forward! Now we can parallelize development of new challenges and do other improvements!

@commjoen commjoen merged commit 5382f31 into master Dec 6, 2023
13 of 15 checks passed
@commjoen commjoen deleted the nbaars/config-challenges branch December 6, 2023 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A way to disable challenge categories
4 participants