From 62b1ac10e8c5e2e21ce1d0ad91897db3f6a5e0c9 Mon Sep 17 00:00:00 2001 From: arcuri82 Date: Fri, 31 Jan 2025 13:56:20 +0100 Subject: [PATCH] #1159: better error message if issues in em.yaml --- .../kotlin/org/evomaster/core/EMConfig.kt | 13 +++-- .../evomaster/core/config/ConfigUtilTest.kt | 10 ++++ core/src/test/resources/config/issue1159.yaml | 47 +++++++++++++++++++ 3 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 core/src/test/resources/config/issue1159.yaml diff --git a/core/src/main/kotlin/org/evomaster/core/EMConfig.kt b/core/src/main/kotlin/org/evomaster/core/EMConfig.kt index c64cbb2e37..7337a19871 100644 --- a/core/src/main/kotlin/org/evomaster/core/EMConfig.kt +++ b/core/src/main/kotlin/org/evomaster/core/EMConfig.kt @@ -355,9 +355,16 @@ class EMConfig { LoggingUtil.uniqueUserInfo("Loading configuration file from: ${Path(configPath).toAbsolutePath()}") } - val cf = ConfigUtil.readFromFile(configPath) - cf.validateAndNormalizeAuth() - return cf + try { + val cf = ConfigUtil.readFromFile(configPath) + cf.validateAndNormalizeAuth() + return cf + }catch (e: Exception){ + val cause = if(e.cause!=null) "\nCause:${e.cause!!.message}" else "" + throw ConfigProblemException("Failed when reading configuration file at $configPath." + + "\nError: ${e.message}" + + "$cause") + } } private fun applyConfigFromFile(cff: ConfigsFromFile) { diff --git a/core/src/test/kotlin/org/evomaster/core/config/ConfigUtilTest.kt b/core/src/test/kotlin/org/evomaster/core/config/ConfigUtilTest.kt index a6b84f1e76..304806ed1d 100644 --- a/core/src/test/kotlin/org/evomaster/core/config/ConfigUtilTest.kt +++ b/core/src/test/kotlin/org/evomaster/core/config/ConfigUtilTest.kt @@ -80,4 +80,14 @@ class ConfigUtilTest{ assertTrue(config.auth.any { it.loginEndpointAuth.payloadUserPwd == null && it.loginEndpointAuth.payloadRaw != null}) assertTrue(config.auth.any { it.loginEndpointAuth.payloadUserPwd != null && it.loginEndpointAuth.payloadRaw == null}) } + + + @Test + fun testIssue1159(){ + + val path = "${basePath}/issue1159.yaml" + org.junit.jupiter.api.assertThrows { + val config = ConfigUtil.readFromFile(path) + } + } } \ No newline at end of file diff --git a/core/src/test/resources/config/issue1159.yaml b/core/src/test/resources/config/issue1159.yaml new file mode 100644 index 0000000000..11c2986984 --- /dev/null +++ b/core/src/test/resources/config/issue1159.yaml @@ -0,0 +1,47 @@ +#https://github.com/WebFuzzing/EvoMaster/issues/1159 + +configs: # remove this {} when specifying properties + bbSwaggerUrl: "http://obedocumentation.fwh.is/?i=1" + bbTargetUrl: "http://obedocumentation.fwh.is/?i=1" + blackBox: true + configPath: "em.yaml" + endpointFocus: null + endpointPrefix: null + endpointTagFilter: null + # header0: "" + # header1: "" + # header2: "" + maxTime: "60s" + outputFilePrefix: "EvoMaster" + outputFileSuffix: "Test" + outputFolder: "generated_tests" + outputFormat: "DEFAULT" + prematureStop: "" + ratePerMinute: 0 + sutControllerHost: "localhost" + sutControllerPort: 40100 + testTimeout: 60 + + +auth: + - name: i gede + loginEndpointAuth: + payloadRaw: "{\"email\": \"igsusrama.if@upnjatim.ac.id\", \"password\": \"sainsdata\"}" + - name: susrama + loginEndpointAuth: + payloadUserPwd: + email: igsusrama.if@upnjatim.ac.id + password: "sainsdata" + usernameField: email + passwordField: password + token: + headerPrefix: "Bearer " + extractFromField: "/token/authToken" + httpHeaderName: "Authorization" + +authTemplate: + loginEndpointAuth: + endpoint: /login + verb: POST + contentType: application/json + expectCookies: true \ No newline at end of file