Skip to content

Commit 9377826

Browse files
authored
Merge branch 'master' into ssrf-url-name-test
2 parents e873094 + 4a89841 commit 9377826

117 files changed

Lines changed: 1862 additions & 1783 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

core-tests/e2e-tests/spring/spring-rest-openapi-v3/src/main/kotlin/com/foo/rest/examples/spring/openapi/v3/dtoreflectiveassert/DtoReflectiveAssertRest.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,14 @@ class DtoReflectiveAssertRest {
4444
return ResponseEntity.ok("OK")
4545
}
4646

47+
@PostMapping(path = ["/enum-examples"], consumes = [MediaType.APPLICATION_JSON_VALUE])
48+
open fun enumExamples(@RequestBody body: EnumExamplesDto) : ResponseEntity<String>{
49+
return ResponseEntity.ok("OK")
50+
}
51+
52+
@PostMapping(path = ["/enum-type"], consumes = [MediaType.APPLICATION_JSON_VALUE])
53+
open fun enumType(@RequestBody body: EnumTypeDto) : ResponseEntity<String>{
54+
return ResponseEntity.ok("OK")
55+
}
56+
4757
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.foo.rest.examples.spring.openapi.v3.dtoreflectiveassert
2+
3+
class EnumExamplesDto {
4+
5+
var textValue: String = ""
6+
var flagValue: Boolean = false
7+
var countValue: Int = -1
8+
var scoreValue: Float = -3.14f
9+
var listValue: List<String> = emptyList()
10+
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.foo.rest.examples.spring.openapi.v3.dtoreflectiveassert
2+
3+
class EnumTypeDto {
4+
5+
var name: String = ""
6+
var status: String = ""
7+
var intStatus: Int = -10
8+
9+
}

core-tests/e2e-tests/spring/spring-rest-openapi-v3/src/main/resources/static/openapi-dto-reflective-assert.yaml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,30 @@ paths:
166166
responses:
167167
'200':
168168
description: OK
169+
/enum-type:
170+
post:
171+
summary: Create an item using enums
172+
requestBody:
173+
required: true
174+
content:
175+
application/json:
176+
schema:
177+
$ref: '#/components/schemas/EnumType'
178+
responses:
179+
'200':
180+
description: OK
181+
/enum-examples:
182+
post:
183+
summary: Submit an object using examples
184+
requestBody:
185+
required: true
186+
content:
187+
application/json:
188+
schema:
189+
$ref: '#/components/schemas/EnumExample'
190+
responses:
191+
'200':
192+
description: OK
169193

170194
components:
171195
schemas:
@@ -211,3 +235,47 @@ components:
211235
required:
212236
- name
213237
- age
238+
239+
EnumType:
240+
type: object
241+
properties:
242+
name:
243+
type: string
244+
status:
245+
type: string
246+
enum: [ active, inactive, archived ]
247+
intStatus:
248+
type: integer
249+
enum: [ -1, 0, 1 ]
250+
required:
251+
- name
252+
- status
253+
- intStatus
254+
255+
EnumExample:
256+
type: object
257+
properties:
258+
textValue:
259+
type: string
260+
example: "hello world"
261+
flagValue:
262+
type: boolean
263+
example: true
264+
countValue:
265+
type: integer
266+
example: 33
267+
scoreValue:
268+
type: number
269+
format: float
270+
example: 3.14
271+
listValue:
272+
type: array
273+
items:
274+
type: string
275+
example: [ "s1", "s2", "s3" ]
276+
required:
277+
- textValue
278+
- flagValue
279+
- countValue
280+
- scoreValue
281+
- listValue

core-tests/e2e-tests/spring/spring-rest-openapi-v3/src/test/kotlin/org/evomaster/e2etests/spring/openapi/v3/dtoreflectiveassert/DtoReflectiveAssertEMTest.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class DtoReflectiveAssertEMTest: SpringTestBase() {
4343
assertHasAtLeastOne(solution, HttpVerb.POST, 200, "/parent", "OK")
4444
assertHasAtLeastOne(solution, HttpVerb.POST, 200, "/items-inline", "OK")
4545
assertHasAtLeastOne(solution, HttpVerb.POST, 200, "/items-components", "OK")
46+
assertHasAtLeastOne(solution, HttpVerb.POST, 200, "/enum-type", "OK")
47+
assertHasAtLeastOne(solution, HttpVerb.POST, 200, "/enum-examples", "OK")
4648
}
4749

4850
assertPrimitiveTypeDtoCreated()
@@ -51,6 +53,8 @@ class DtoReflectiveAssertEMTest: SpringTestBase() {
5153
assertItemsInlineDtoCreated()
5254
assertAnyOfDtoCreated()
5355
assertOneOfDtoCreated()
56+
assertEnumTypeDtoCreated()
57+
assertEnumExampleDtoCreated()
5458
}
5559

5660
private fun assertPrimitiveTypeDtoCreated() {
@@ -107,6 +111,22 @@ class DtoReflectiveAssertEMTest: SpringTestBase() {
107111
assertProperty(klass, instance, "mouse", "Jerry")
108112
}
109113

114+
private fun assertEnumTypeDtoCreated() {
115+
val (klass, instance) = initDtoClass("EnumType")
116+
assertProperty(klass, instance, "name", "EvoMaster")
117+
assertProperty(klass, instance, "status", "active")
118+
assertProperty(klass, instance, "intStatus", 1)
119+
}
120+
121+
private fun assertEnumExampleDtoCreated() {
122+
val (klass, instance) = initDtoClass("EnumExample")
123+
assertProperty(klass, instance, "textValue", "A text value")
124+
assertProperty(klass, instance, "flagValue", true)
125+
assertProperty(klass, instance, "countValue", 33)
126+
assertProperty(klass, instance, "scoreValue", 3.14f)
127+
assertProperty(klass, instance, "listValue", mutableListOf("s1", "s2", "s3"))
128+
}
129+
110130
private fun initDtoClass(name: String): Pair<KClass<out Any>, Any> {
111131
val className = ClassName("org.foo.dto.$name")
112132
val klass = loadClass(className).kotlin

core-tests/e2e-tests/spring/spring-rest-openapi-v3/src/test/kotlin/org/evomaster/e2etests/spring/openapi/v3/oracledisable/SSRFBaseDisableEMTest.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ class SSRFBaseDisableEMTest : SpringTestBase() {
3939
setOption(args, "schemaOracles", "false")
4040
setOption(args, "disabledOracleCodes", DefinedFaultCategory.SSRF.code.toString())
4141

42-
// TODO: Remove once EnumGene is supported for DTOs
43-
setOption(args, "dtoForRequestPayload","false")
44-
4542
val solution = initAndRun(args)
4643

4744
assertTrue(solution.individuals.isNotEmpty())

core-tests/e2e-tests/spring/spring-rest-openapi-v3/src/test/kotlin/org/evomaster/e2etests/spring/openapi/v3/security/ssrf/base/SSRFBaseEMTest.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ class SSRFBaseEMTest : SpringTestBase() {
3737
setOption(args, "languageModelConnector", "false")
3838
setOption(args, "schemaOracles", "false")
3939

40-
// TODO: Remove once EnumGene is supported for DTOs
41-
setOption(args, "dtoForRequestPayload","false")
42-
4340
val solution = initAndRun(args)
4441

4542
assertTrue(solution.individuals.isNotEmpty())

core-tests/e2e-tests/spring/spring-rest-openapi-v3/src/test/kotlin/org/evomaster/e2etests/spring/openapi/v3/swagger/SwaggerDescriptionEMTest.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ class SwaggerDescriptionEMTest : SpringTestBase() {
2626
500
2727
) { args: MutableList<String> ->
2828

29-
// TODO: Remove once EnumGene is supported for DTOs
30-
setOption(args, "dtoForRequestPayload","false")
31-
3229
val solution = initAndRun(args)
3330

3431
Assertions.assertTrue(solution.individuals.isNotEmpty())

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,7 @@ class EMConfig {
11621162

11631163
enum class Algorithm {
11641164
DEFAULT, SMARTS, MIO, RANDOM, WTS, MOSA, RW,
1165-
StandardGA, MonotonicGA, SteadyStateGA, BreederGA, CellularGA, OnePlusLambdaLambdaGA, MuLambdaEA, MuPlusLambdaEA, LIPS // GA variants still work-in-progress.
1165+
StandardGA, MonotonicGA, SteadyStateGA, BreederGA, CellularGA, OnePlusLambdaLambdaGA, MuLambdaEA, MuPlusLambdaEA, LIPS, CRO // GA variants still work-in-progress.
11661166
}
11671167

11681168
@Cfg("The algorithm used to generate test cases. The default depends on whether black-box or white-box testing is done.")
@@ -1575,6 +1575,27 @@ class EMConfig {
15751575
@Min(1.0)
15761576
var tournamentSize = 10
15771577

1578+
// --- Chemical Reaction Optimization (CRO) parameters ---
1579+
@Cfg("CRO: Molecular collision rate c_r (probability of binary reactions)")
1580+
@Probability
1581+
var croMolecularCollisionRate: Double = 0.2
1582+
1583+
@Cfg("CRO: Kinetic energy loss rate k_r (lower bound of retained fraction after on-wall)")
1584+
@Probability
1585+
var croKineticEnergyLossRate: Double = 0.2
1586+
1587+
@Cfg("CRO: Initial kinetic energy assigned to each molecule")
1588+
@Min(0.0)
1589+
var croInitialKineticEnergy: Double = 1000.0
1590+
1591+
@Cfg("CRO: Decomposition threshold d_t (min number of collisions before decomposition)")
1592+
@Min(0.0)
1593+
var croDecompositionThreshold: Int = 500
1594+
1595+
@Cfg("CRO: Synthesis KE threshold s_t (molecule can synthesize if KE ≤ s_t)")
1596+
@Min(0.0)
1597+
var croSynthesisThreshold: Double = 10.0
1598+
15781599
@Cfg("When sampling new test cases to evaluate, probability of using some smart strategy instead of plain random")
15791600
@Probability
15801601
var probOfSmartSampling = 0.95

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,9 @@ class Main {
791791
EMConfig.Algorithm.OnePlusLambdaLambdaGA ->
792792
Key.get(object : TypeLiteral<OnePlusLambdaLambdaGeneticAlgorithm<RestIndividual>>() {})
793793

794+
EMConfig.Algorithm.CRO ->
795+
Key.get(object : TypeLiteral<CroAlgorithm<RestIndividual>>() {})
796+
794797
else -> throw IllegalStateException("Unrecognized algorithm ${config.algorithm}")
795798
}
796799
}

0 commit comments

Comments
 (0)