Skip to content

Commit

Permalink
#1159: better error message if issues in em.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
arcuri82 committed Jan 31, 2025
1 parent a694858 commit 62b1ac1
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
13 changes: 10 additions & 3 deletions core/src/main/kotlin/org/evomaster/core/EMConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions core/src/test/kotlin/org/evomaster/core/config/ConfigUtilTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<IllegalArgumentException> {
val config = ConfigUtil.readFromFile(path)
}
}
}
47 changes: 47 additions & 0 deletions core/src/test/resources/config/issue1159.yaml
Original file line number Diff line number Diff line change
@@ -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\": \"[email protected]\", \"password\": \"sainsdata\"}"
- name: susrama
loginEndpointAuth:
payloadUserPwd:
email: [email protected]
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

0 comments on commit 62b1ac1

Please sign in to comment.