Skip to content

Commit 69379bb

Browse files
committed
better error handling, and fixed broken backward compatibility of new 'base'
1 parent ce65b67 commit 69379bb

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

core/src/main/kotlin/org/evomaster/core/EMConfig.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,9 @@ class EMConfig {
12541254

12551255
@Deprecated("Rather use 'base'")
12561256
@Cfg("Old, deprecated parameter for 'base'.")
1257-
var bbTargetUrl: String = ""
1257+
var bbTargetUrl: String
1258+
get() = base
1259+
set(value) { base = value }
12581260

12591261
@Important(3.7)
12601262
@Cfg("Rate limiter, of how many actions to do per minute. For example, when making HTTP calls towards" +

core/src/main/kotlin/org/evomaster/core/problem/rest/BlackBoxUtils.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ object BlackBoxUtils {
1818
fun targetUrl(config: EMConfig, sampler: Sampler<*>? = null): String {
1919

2020
/*
21-
Note: bbTargetUrl and bbSwaggerUrl are already validated
21+
Note: base and schema are already validated
2222
in EMConfig (but they can be blank)
2323
*/
2424

25-
if (config.bbTargetUrl.isNotBlank()) {
25+
if (config.base.isNotBlank()) {
2626
//this has the priority
27-
return config.bbTargetUrl
27+
return config.base
2828
} else {
2929

3030
when (config.problemType) {
@@ -40,17 +40,24 @@ object BlackBoxUtils {
4040
So, going to use same location as where the schema was downloaded from,
4141
as specified in the specs to do in these cases
4242
*/
43-
extractTarget(config.bbSwaggerUrl)
43+
extractTarget(config.schema)
4444
} else {
4545
//OpenAPI specs call it a "url", but it is actually a URI
46+
//TODO should check all 'servers' entries, especially if we get issues in resolving target
4647
val uri = schema.servers[0].url
4748
if(uri.startsWith("//")){
4849
// this can happen if 'scheme' is missing in V2, resulting in an invalid URL in current parser.
4950
// this is also a valid value in V3
5051
extractTarget("http:$uri")
5152
} else if(uri.startsWith("/")){
52-
//this is a relative URI, so get info from schema location
53-
extractTarget(config.bbSwaggerUrl)
53+
//this is a relative URI, so get info from schema location... but only if it is a valid URL
54+
if(!config.schema.startsWith("http")){
55+
throw SutProblemException("Schema has no servers[0] entry with a URL." +
56+
" As the schema was not downloaded from a URL, EvoMaster cannot infer the" +
57+
" location of the API." +
58+
" Use '--base URL' to specify it manually")
59+
}
60+
extractTarget(config.schema)
5461
} else {
5562
extractTarget(uri)
5663
}

0 commit comments

Comments
 (0)