Permalink
Browse files

fixed bug, now auth tests pass

  • Loading branch information...
arcuri82 committed Dec 3, 2018
1 parent 003c474 commit 8888407b03063d8a7f3bdcc55e0a407378c4d450
@@ -20,9 +20,10 @@ object DbActionTransformer {
val action = insertions[i]
if(action.representExistingData){
/*
FIXME even if not "printable", should still be able
to point to it. Logic below needs to be updated.
Even if not going to be part of the DTO, should still be able
to point to it with FKs
*/
previous.addAll(action.seeGenes())
continue
}
@@ -152,7 +152,7 @@ object DbActionUtils {
val uniqueColumnValues = mutableMapOf<Pair<String, String>, MutableSet<Gene>>()
for ((actionIndex, action) in actions.withIndex()) {
if (action !is DbAction) {
if (action !is DbAction || action.representExistingData) {
continue
}
@@ -226,7 +226,8 @@ class SqlInsertBuilder(
for(i in 0 until pks.size){
val pkName = pks[i].name
val data = ImmutableDataHolderGene(pkName, r.columnData[i])
val inQuotes = pks[i].type.shouldBePrintedInQuotes()
val data = ImmutableDataHolderGene(pkName, r.columnData[i], inQuotes)
val pk = SqlPrimaryKeyGene(pkName, table.name, data, id)
genes.add(pk)
}
@@ -74,5 +74,11 @@ enum class ColumnDataType(dataTypeName: String) {
/**
* A Binary Large Object, typically images, audio or multimedia.
*/
BLOB("BLOB")
BLOB("BLOB");
fun shouldBePrintedInQuotes() : Boolean {
return equals(VARCHAR) || equals(CHAR) || equals(TIMESTAMP)
}
}
@@ -58,8 +58,7 @@ class RestStructureMutator : StructureMutator() {
missing = findMissing(es, ind)
}
//TODO put back once bug fixed
//ind.dbInitialization.addAll(0, sampler.existingSqlData)
ind.dbInitialization.addAll(0, sampler.existingSqlData)
if (config.generateSqlDataWithDSE) {
//TODO DSE could be plugged in here
@@ -11,7 +11,7 @@ import org.evomaster.core.search.service.Randomness
* A typical example is a Primary Key in a database, and we want
* a Foreign Key pointing to it
*/
class ImmutableDataHolderGene(name: String, val value: String) : Gene(name){
class ImmutableDataHolderGene(name: String, val value: String, val inQuotes: Boolean) : Gene(name){
override fun copy(): Gene {
return this // recall it is immutable
@@ -27,6 +27,10 @@ class ImmutableDataHolderGene(name: String, val value: String) : Gene(name){
}
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?): String {
if(inQuotes){
return "\"$value\""
}
return value
}
@@ -1,16 +1,13 @@
package com.foo.rest.examples.spring.db.auth.db;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
@Entity
public class AuthProjectEntity {
@Id @GeneratedValue
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotBlank
@@ -15,12 +15,12 @@
@Test
public void testRunEM() throws Throwable {
//handleFlaky(() -> {
handleFlaky(() -> {
String[] args = new String[]{
"--createTests", "true",
"--seed", "42",
"--sutControllerPort", "" + controllerPort,
"--maxActionEvaluations", "1000",
"--maxActionEvaluations", "500",
"--stoppingCriterion", "FITNESS_EVALUATIONS",
"--heuristicsForSQL", "true",
"--generateSqlDataWithSearch", "true"
@@ -30,10 +30,10 @@ public void testRunEM() throws Throwable {
assertTrue(solution.getIndividuals().size() >= 1);
assertHasAtLeastOne(solution, HttpVerb.GET, 200, "/api/db/users", null);
assertHasAtLeastOne(solution, HttpVerb.GET, 401, "/api/db/projects", null);
assertHasAtLeastOne(solution, HttpVerb.GET, 400, "/api/db/projects", null);
assertHasAtLeastOne(solution, HttpVerb.GET, 200, "/api/db/projects", null);
//});
assertHasAtLeastOne(solution, HttpVerb.GET, 200, "/api/db/auth/users", null);
assertHasAtLeastOne(solution, HttpVerb.GET, 401, "/api/db/auth/projects", null);
assertHasAtLeastOne(solution, HttpVerb.GET, 400, "/api/db/auth/projects", null);
assertHasAtLeastOne(solution, HttpVerb.GET, 200, "/api/db/auth/projects", null);
});
}
}
@@ -1,9 +1,13 @@
package org.evomaster.e2etests.spring.examples.db.auth;
import io.restassured.http.ContentType;
import org.evomaster.client.java.controller.api.dto.database.operations.InsertionDto;
import org.junit.jupiter.api.Test;
import java.util.List;
import static io.restassured.RestAssured.given;
import static org.evomaster.client.java.controller.db.dsl.SqlDsl.sql;
import static org.hamcrest.CoreMatchers.equalTo;
public class DbAuthManualTest extends DbAuthTestBase{
@@ -47,4 +51,24 @@ public void testAuthorizedButNoData(){
.statusCode(400);
}
@Test
public void testAuthorizedWithData(){
List<InsertionDto> dtos = sql()
.insertInto("Auth_Project_Entity")
.d("name", "\"whatever\"")
.d("owner_user_id ", "\"foo\"")
.dtos();
controller.execInsertionsIntoDatabase(dtos);
String url = baseUrlOfSut + "/api/db/auth/projects";
given().accept(ContentType.JSON)
.auth().basic("foo","123")
.get(url)
.then()
.statusCode(200);
}
}

0 comments on commit 8888407

Please sign in to comment.