■ ■ ■ ■ ■ ■
src/main/java/org/owasp/wrongsecrets/challenges/ChallengeUI.java
skipped 25 lines 26 26 this.runtimeEnvironment = runtimeEnvironment; 27 27 } 28 28 29 + /** 30 + * Converts the name of the class into the challenge name. 31 + * @return String with name of the challenge. 32 + */ 29 33 public String getName() { 30 34 var matchers = challengePattern.matcher(challenge.getClass().getSimpleName()); 31 35 if (matchers.matches()) { skipped 2 lines 34 38 return "Unknown"; 35 39 } 36 40 41 + /** 42 + * gives back the number of the challenge. 43 + * @return int with challenge number. 44 + */ 37 45 public Integer getLink() { 38 46 return challengeNumber; 39 47 } 40 48 49 + /** 50 + * Returns the tech used for a challenge. 51 + * @return string with tech. 52 + */ 41 53 public String getTech() { 42 54 return challenge.getTech(); 43 55 } 44 56 57 + /** 58 + * Returns the number of the next challenge (e.g current+1). 59 + * @return int with next challenge number. 60 + */ 45 61 public Integer next() { 46 62 return challengeNumber + 1; 47 63 } 48 64 65 + /** 66 + * Returns the number of the previous challenge (e.g current-1). 67 + * @return int with previous challenge number. 68 + */ 49 69 public Integer previous() { 50 70 return challengeNumber - 1; 51 71 } 52 72 73 + /** 74 + * Returns filename of the explanation of the challenge. 75 + * @return String with filename. 76 + */ 53 77 public String getExplanation() { 54 78 return challenge.getExplanation(); 55 79 } 56 80 81 + /** 82 + * Returns filename of the hints for the challenge. 83 + * @return String with filename. 84 + */ 57 85 public String getHint() { 58 86 List<RuntimeEnvironment.Environment> limitedOnlineEnvs = List.of(RuntimeEnvironment.Environment.HEROKU_DOCKER, RuntimeEnvironment.Environment.FLY_DOCKER, RuntimeEnvironment.Environment.OKTETO_K8S); 59 87 if (limitedOnlineEnvs.contains(runtimeEnvironment.getRuntimeEnvironment()) && challenge.isLimittedWhenOnlineHosted()) { skipped 2 lines 62 90 return challenge.getHint(); 63 91 } 64 92 93 + /** 94 + * Returns filename of the reasons of the challenge. 95 + * @return String with filename. 96 + */ 65 97 public String getReason() { 66 98 return challenge.getReason(); 67 99 } 68 100 101 + /** 102 + * String providing the minimal required env. Used in homescreen. 103 + * @return String with required env. 104 + */ 69 105 public String requiredEnv() { 70 106 return challenge.supportedRuntimeEnvironments().stream() 71 107 .map(Enum::name) skipped 1 lines 73 109 .collect(Collectors.joining()); 74 110 } 75 111 112 + /** 113 + * returns integer with difficulty of the challenge. 114 + * @return int 115 + */ 76 116 public int difficulty() { 77 117 return challenge.difficulty(); 78 118 } 79 119 120 + /** 121 + * checks whether challenge is enabled based on used runtimemode and CTF enablement. 122 + * @return boolean true if the challenge can run. 123 + */ 80 124 public boolean isChallengeEnabled() { 81 125 if (runtimeEnvironment.runtimeInCTFMode()) { 82 126 return runtimeEnvironment.canRun(challenge) && challenge.canRunInCTFMode(); skipped 1 lines 84 128 return runtimeEnvironment.canRun(challenge); 85 129 } 86 130 131 + /** 132 + * returns the list of challengeUIs based on the status sof the runtime. 133 + * @param challenges actual challenges to be used in app. 134 + * @param environment the runtime env we are running on as an app. 135 + * @return list of ChallengeUIs. 136 + */ 87 137 public static List<ChallengeUI> toUI(List<Challenge> challenges, RuntimeEnvironment environment) { 88 138 return challenges.stream() 89 139 .sorted(Comparator.comparingInt(challenge -> Integer.parseInt(challenge.getClass().getSimpleName().replace("Challenge", "")))) skipped 5 lines