mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 14:07:55 +01:00
fixed remaining non-idempotent tests (#758)
This commit is contained in:
parent
11ae0ea7d3
commit
8f1ff56d34
@ -37,7 +37,10 @@ public class TestAppResource extends BaseJerseyTest {
|
|||||||
* Test the API resource.
|
* Test the API resource.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Record if config has been changed by previous test runs
|
||||||
private static boolean configInboxChanged = false;
|
private static boolean configInboxChanged = false;
|
||||||
|
private static boolean configSmtpChanged = false;
|
||||||
|
private static boolean configLdapChanged = false;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAppResource() {
|
public void testAppResource() {
|
||||||
@ -191,6 +194,12 @@ public class TestAppResource extends BaseJerseyTest {
|
|||||||
target().path("/document/list").request()
|
target().path("/document/list").request()
|
||||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, guestToken)
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, guestToken)
|
||||||
.get(JsonObject.class);
|
.get(JsonObject.class);
|
||||||
|
|
||||||
|
// Disable guest login (clean up state)
|
||||||
|
target().path("/app/guest_login").request()
|
||||||
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||||
|
.post(Entity.form(new Form()
|
||||||
|
.param("enabled", "false")), JsonObject.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -205,11 +214,13 @@ public class TestAppResource extends BaseJerseyTest {
|
|||||||
JsonObject json = target().path("/app/config_smtp").request()
|
JsonObject json = target().path("/app/config_smtp").request()
|
||||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||||
.get(JsonObject.class);
|
.get(JsonObject.class);
|
||||||
|
if (!configSmtpChanged) {
|
||||||
Assert.assertTrue(json.isNull("hostname"));
|
Assert.assertTrue(json.isNull("hostname"));
|
||||||
Assert.assertTrue(json.isNull("port"));
|
Assert.assertTrue(json.isNull("port"));
|
||||||
Assert.assertTrue(json.isNull("username"));
|
Assert.assertTrue(json.isNull("username"));
|
||||||
Assert.assertTrue(json.isNull("password"));
|
Assert.assertTrue(json.isNull("password"));
|
||||||
Assert.assertTrue(json.isNull("from"));
|
Assert.assertTrue(json.isNull("from"));
|
||||||
|
}
|
||||||
|
|
||||||
// Change SMTP configuration
|
// Change SMTP configuration
|
||||||
target().path("/app/config_smtp").request()
|
target().path("/app/config_smtp").request()
|
||||||
@ -220,6 +231,7 @@ public class TestAppResource extends BaseJerseyTest {
|
|||||||
.param("username", "sismics")
|
.param("username", "sismics")
|
||||||
.param("from", "contact@sismics.com")
|
.param("from", "contact@sismics.com")
|
||||||
), JsonObject.class);
|
), JsonObject.class);
|
||||||
|
configSmtpChanged = true;
|
||||||
|
|
||||||
// Get SMTP configuration
|
// Get SMTP configuration
|
||||||
json = target().path("/app/config_smtp").request()
|
json = target().path("/app/config_smtp").request()
|
||||||
@ -389,7 +401,9 @@ public class TestAppResource extends BaseJerseyTest {
|
|||||||
JsonObject json = target().path("/app/config_ldap").request()
|
JsonObject json = target().path("/app/config_ldap").request()
|
||||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||||
.get(JsonObject.class);
|
.get(JsonObject.class);
|
||||||
|
if (!configLdapChanged) {
|
||||||
Assert.assertFalse(json.getBoolean("enabled"));
|
Assert.assertFalse(json.getBoolean("enabled"));
|
||||||
|
}
|
||||||
|
|
||||||
// Change LDAP configuration
|
// Change LDAP configuration
|
||||||
target().path("/app/config_ldap").request()
|
target().path("/app/config_ldap").request()
|
||||||
@ -406,6 +420,7 @@ public class TestAppResource extends BaseJerseyTest {
|
|||||||
.param("default_email", "devnull@teedy.io")
|
.param("default_email", "devnull@teedy.io")
|
||||||
.param("default_storage", "100000000")
|
.param("default_storage", "100000000")
|
||||||
), JsonObject.class);
|
), JsonObject.class);
|
||||||
|
configLdapChanged = true;
|
||||||
|
|
||||||
// Get the LDAP configuration
|
// Get the LDAP configuration
|
||||||
json = target().path("/app/config_ldap").request()
|
json = target().path("/app/config_ldap").request()
|
||||||
|
@ -118,6 +118,12 @@ public class TestAuditLogResource extends BaseJerseyTest {
|
|||||||
Assert.assertEquals(countByClass(logs, "Document"), 1);
|
Assert.assertEquals(countByClass(logs, "Document"), 1);
|
||||||
Assert.assertEquals(countByClass(logs, "Acl"), 2);
|
Assert.assertEquals(countByClass(logs, "Acl"), 2);
|
||||||
Assert.assertEquals(countByClass(logs, "File"), 1);
|
Assert.assertEquals(countByClass(logs, "File"), 1);
|
||||||
|
|
||||||
|
// Delete auditlog1
|
||||||
|
String adminToken = adminToken();
|
||||||
|
target().path("/user/auditlog1").request()
|
||||||
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||||
|
.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -188,5 +188,25 @@ public class TestGroupResource extends BaseJerseyTest {
|
|||||||
Assert.assertEquals(2, groups.size());
|
Assert.assertEquals(2, groups.size());
|
||||||
Assert.assertTrue(groupList.contains("g11"));
|
Assert.assertTrue(groupList.contains("g11"));
|
||||||
Assert.assertTrue(groupList.contains("g112"));
|
Assert.assertTrue(groupList.contains("g112"));
|
||||||
|
|
||||||
|
// Delete all remaining groups and users
|
||||||
|
target().path("/group/g11").request()
|
||||||
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||||
|
.delete(JsonObject.class);
|
||||||
|
target().path("/group/g12new").request()
|
||||||
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||||
|
.delete(JsonObject.class);
|
||||||
|
target().path("/group/g111").request()
|
||||||
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||||
|
.delete(JsonObject.class);
|
||||||
|
target().path("/group/g112").request()
|
||||||
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||||
|
.delete(JsonObject.class);
|
||||||
|
target().path("/user/group1").request()
|
||||||
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||||
|
.delete();
|
||||||
|
target().path("/user/admin2").request()
|
||||||
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||||
|
.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,5 +137,10 @@ public class TestRouteModelResource extends BaseJerseyTest {
|
|||||||
.get(JsonObject.class);
|
.get(JsonObject.class);
|
||||||
routeModels = json.getJsonArray("routemodels");
|
routeModels = json.getJsonArray("routemodels");
|
||||||
Assert.assertEquals(1, routeModels.size());
|
Assert.assertEquals(1, routeModels.size());
|
||||||
|
|
||||||
|
// Deletes routeModel1 user
|
||||||
|
target().path("/user/routeModel1").request()
|
||||||
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||||
|
.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,6 +73,12 @@ public class TestSecurity extends BaseJerseyTest {
|
|||||||
|
|
||||||
// User testsecurity logs out
|
// User testsecurity logs out
|
||||||
clientUtil.logout(testSecurityToken);
|
clientUtil.logout(testSecurityToken);
|
||||||
|
|
||||||
|
// Delete the user
|
||||||
|
String adminToken = adminToken();
|
||||||
|
target().path("/user/testsecurity").request()
|
||||||
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||||
|
.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -98,5 +104,11 @@ public class TestSecurity extends BaseJerseyTest {
|
|||||||
.header(HeaderBasedSecurityFilter.AUTHENTICATED_USER_HEADER, "idontexist")
|
.header(HeaderBasedSecurityFilter.AUTHENTICATED_USER_HEADER, "idontexist")
|
||||||
.get()
|
.get()
|
||||||
.getStatus());
|
.getStatus());
|
||||||
|
|
||||||
|
// Delete the user
|
||||||
|
String adminToken = adminToken();
|
||||||
|
target().path("/user/header_auth_test").request()
|
||||||
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||||
|
.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -127,5 +127,14 @@ public class TestShareResource extends BaseJerseyTest {
|
|||||||
Assert.assertEquals(Status.BAD_REQUEST, Status.fromStatusCode(response.getStatus()));
|
Assert.assertEquals(Status.BAD_REQUEST, Status.fromStatusCode(response.getStatus()));
|
||||||
json = response.readEntity(JsonObject.class);
|
json = response.readEntity(JsonObject.class);
|
||||||
Assert.assertEquals("ShareNotFound", json.getString("type"));
|
Assert.assertEquals("ShareNotFound", json.getString("type"));
|
||||||
|
|
||||||
|
// Deletes share1 and share 2
|
||||||
|
String adminToken = adminToken();
|
||||||
|
target().path("/user/share1").request()
|
||||||
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||||
|
.delete();
|
||||||
|
target().path("/user/share2").request()
|
||||||
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||||
|
.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -230,5 +230,11 @@ public class TestTagResource extends BaseJerseyTest {
|
|||||||
Assert.assertEquals(1, tags.size());
|
Assert.assertEquals(1, tags.size());
|
||||||
Assert.assertEquals("UpdatedName", tags.getJsonObject(0).getString("name"));
|
Assert.assertEquals("UpdatedName", tags.getJsonObject(0).getString("name"));
|
||||||
Assert.assertNull(tags.getJsonObject(0).get("parent"));
|
Assert.assertNull(tags.getJsonObject(0).get("parent"));
|
||||||
|
|
||||||
|
// Deletes user tag1
|
||||||
|
String adminToken = adminToken();
|
||||||
|
target().path("/user/tag1").request()
|
||||||
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||||
|
.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -103,5 +103,13 @@ public class TestThemeResource extends BaseJerseyTest {
|
|||||||
// Get the background
|
// Get the background
|
||||||
response = target().path("/theme/image/background").request().get();
|
response = target().path("/theme/image/background").request().get();
|
||||||
Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
|
Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
|
||||||
|
|
||||||
|
// Reset the main color as admin
|
||||||
|
target().path("/theme").request()
|
||||||
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||||
|
.post(Entity.form(new Form()
|
||||||
|
.param("color", "#ffffff")
|
||||||
|
.param("name", "Teedy")
|
||||||
|
.param("css", "")), JsonObject.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -230,6 +230,11 @@ public class TestUserResource extends BaseJerseyTest {
|
|||||||
.param("username", "alice")
|
.param("username", "alice")
|
||||||
.param("password", "12345678")));
|
.param("password", "12345678")));
|
||||||
Assert.assertEquals(Status.FORBIDDEN, Status.fromStatusCode(response.getStatus()));
|
Assert.assertEquals(Status.FORBIDDEN, Status.fromStatusCode(response.getStatus()));
|
||||||
|
|
||||||
|
// Delete user bob
|
||||||
|
target().path("/user").request()
|
||||||
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, bobToken)
|
||||||
|
.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -416,7 +421,7 @@ public class TestUserResource extends BaseJerseyTest {
|
|||||||
response = target().path("/user/totp1").request()
|
response = target().path("/user/totp1").request()
|
||||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||||
.delete();
|
.delete();
|
||||||
Assert.assertEquals(200, response.getStatus());
|
Assert.assertEquals(Response.Status.OK, Response.Status.fromStatusCode(response.getStatus()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -489,5 +494,11 @@ public class TestUserResource extends BaseJerseyTest {
|
|||||||
Assert.assertEquals(Response.Status.BAD_REQUEST, Response.Status.fromStatusCode(response.getStatus()));
|
Assert.assertEquals(Response.Status.BAD_REQUEST, Response.Status.fromStatusCode(response.getStatus()));
|
||||||
json = response.readEntity(JsonObject.class);
|
json = response.readEntity(JsonObject.class);
|
||||||
Assert.assertEquals("KeyNotFound", json.getString("type"));
|
Assert.assertEquals("KeyNotFound", json.getString("type"));
|
||||||
|
|
||||||
|
// Delete absent_minded
|
||||||
|
response = target().path("/user/absent_minded").request()
|
||||||
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||||
|
.delete();
|
||||||
|
Assert.assertEquals(Response.Status.OK, Response.Status.fromStatusCode(response.getStatus()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,5 +84,10 @@ public class TestWebhookResource extends BaseJerseyTest {
|
|||||||
.get(JsonObject.class);
|
.get(JsonObject.class);
|
||||||
webhooks = json.getJsonArray("webhooks");
|
webhooks = json.getJsonArray("webhooks");
|
||||||
Assert.assertEquals(0, webhooks.size());
|
Assert.assertEquals(0, webhooks.size());
|
||||||
|
|
||||||
|
// Deletes webhook1
|
||||||
|
target().path("/user/webhook1").request()
|
||||||
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||||
|
.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user