[DEV] update and correct test

This commit is contained in:
Edouard DUPIN 2023-10-23 00:35:21 +02:00
parent 00295b94d1
commit 5256278219
3 changed files with 38 additions and 29 deletions

View File

@ -44,8 +44,17 @@ public class RightResource {
logger.debug("Get some descriptions: {} applicationId={}", rightsDescriptions.size(), applicationId); logger.debug("Get some descriptions: {} applicationId={}", rightsDescriptions.size(), applicationId);
if (rightsDescriptions != null && rightsDescriptions.size() != 0) { if (rightsDescriptions != null && rightsDescriptions.size() != 0) {
final List<Right> rights = getRawUserRight(userId, applicationId); final List<Right> rights = getRawUserRight(userId, applicationId);
logger.debug("Get some user right: {}userID={}", rights.size(), userId); logger.debug("Get some user right: count={} userID={}", rights.size(), userId);
logger.debug("Rights:");
for (final Right elem : rights) {
logger.debug(" - applId={} rightDescriptionId={} value={}", elem.applicationId, elem.rightDescriptionId, elem.value);
}
logger.debug("RightDescription:");
for (final RightDescription elem : rightsDescriptions) {
logger.debug(" - id={} key={} type={} default={}", elem.id, elem.key, elem.type, elem.defaultValue);
}
for (final RightDescription description : rightsDescriptions) { for (final RightDescription description : rightsDescriptions) {
if (description == null) { if (description == null) {
// TODO: this is a really strange case to manage later... // TODO: this is a really strange case to manage later...
continue; continue;

View File

@ -16,7 +16,7 @@ public class Initialization extends MigrationSqlStep {
public String getName() { public String getName() {
return "Initialization"; return "Initialization";
} }
public Initialization() throws Exception { public Initialization() throws Exception {
addClass(Settings.class); addClass(Settings.class);
addClass(UserAuth.class); addClass(UserAuth.class);
@ -44,32 +44,32 @@ public class Initialization extends MigrationSqlStep {
('SIGN_UP_ENABLE', 'rwr-r-', 'BOOLEAN', 'false'), ('SIGN_UP_ENABLE', 'rwr-r-', 'BOOLEAN', 'false'),
('SIGN_IN_ENABLE', 'rwr-r-', 'BOOLEAN', 'true'), ('SIGN_IN_ENABLE', 'rwr-r-', 'BOOLEAN', 'true'),
('SIGN_UP_FILTER', 'rw----', 'STRING', '.*'), ('SIGN_UP_FILTER', 'rw----', 'STRING', '.*'),
('EMAIL_VALIDATION_REQUIRED', 'rwr-r-', 'BOOLEAN', 'false'); ('EMAIL_VALIDATION_REQUIRED', 'rwr-r-', 'BOOLEAN', 'false');
"""); """);
addAction(""" addAction("""
INSERT INTO `rightDescription` (`id`, `applicationId`, `key`, `title`, `description`, `type`) VALUES INSERT INTO `rightDescription` (`id`, `applicationId`, `key`, `title`, `description`, `type`, `defaultValue`) VALUES
(1, 1, 'ADMIN', 'Administrator', 'Full administrator Right', 'BOOLEAN'); (1, 1, 'ADMIN', 'Administrator', 'Full administrator Right', 'BOOLEAN', 'false');
"""); """);
addAction(""" addAction("""
INSERT INTO `right` (`applicationId`, `userId`, `rightDescriptionId`, `value`) VALUES INSERT INTO `right` (`applicationId`, `userId`, `rightDescriptionId`, `value`) VALUES
(1, 1, 1, 'true'); (1, 1, 1, 'true');
"""); """);
// we generate an offset to permit to manage some generic upgrade in the future... // we generate an offset to permit to manage some generic upgrade in the future... (can not be done in sqlite)
addAction(""" addAction("""
ALTER TABLE `application` AUTO_INCREMENT = 1000; ALTER TABLE `application` AUTO_INCREMENT = 1000;
"""); """, "mysql");
addAction(""" addAction("""
ALTER TABLE `user` AUTO_INCREMENT = 1000; ALTER TABLE `user` AUTO_INCREMENT = 1000;
"""); """, "mysql");
addAction(""" addAction("""
ALTER TABLE `settings` AUTO_INCREMENT = 1000; ALTER TABLE `settings` AUTO_INCREMENT = 1000;
"""); """, "mysql");
addAction(""" addAction("""
ALTER TABLE `right` AUTO_INCREMENT = 1000; ALTER TABLE `right` AUTO_INCREMENT = 1000;
"""); """, "mysql");
addAction(""" addAction("""
ALTER TABLE `rightDescription` AUTO_INCREMENT = 1000; ALTER TABLE `rightDescription` AUTO_INCREMENT = 1000;
"""); """, "mysql");
display(); display();
} }

View File

@ -30,7 +30,7 @@ import com.nimbusds.jwt.JWTClaimsSet;
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) @TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class TestBase { public class TestBase {
private final static Logger LOGGER = LoggerFactory.getLogger(TestBase.class); private final static Logger LOGGER = LoggerFactory.getLogger(TestBase.class);
static WebLauncherTest webInterface = null; static WebLauncherTest webInterface = null;
static RESTApi api = null; static RESTApi api = null;
@ -42,11 +42,11 @@ public class TestBase {
Assertions.fail("Can not get Authentication for '" + login + "' ==> " + ex.getMessage()); Assertions.fail("Can not get Authentication for '" + login + "' ==> " + ex.getMessage());
} }
} }
public void loginAdmin() { public void loginAdmin() {
login("karadmin", "adminA@666"); login("karadmin", "adminA@666");
} }
@BeforeAll @BeforeAll
public static void configureWebServer() throws Exception { public static void configureWebServer() throws Exception {
LOGGER.info("configure server ..."); LOGGER.info("configure server ...");
@ -70,7 +70,7 @@ public class TestBase {
webInterface = null; webInterface = null;
// TODO: do it better... // TODO: do it better...
} }
@Order(1) @Order(1)
@Test @Test
//@RepeatedTest(10) //@RepeatedTest(10)
@ -78,13 +78,13 @@ public class TestBase {
final HealthResult result = api.get(HealthResult.class, "health_check"); final HealthResult result = api.get(HealthResult.class, "health_check");
Assertions.assertEquals(result.value(), "alive and kicking"); Assertions.assertEquals(result.value(), "alive and kicking");
} }
@Order(2) @Order(2)
@Test @Test
public void checkHealthCheckWrongAPI() throws Exception { public void checkHealthCheckWrongAPI() throws Exception {
Assertions.assertThrows(RESTErrorResponseExeption.class, () -> api.get(HealthResult.class, "health_checks")); Assertions.assertThrows(RESTErrorResponseExeption.class, () -> api.get(HealthResult.class, "health_checks"));
} }
@Order(3) @Order(3)
@Test @Test
public void firstUserConnect() throws Exception { public void firstUserConnect() throws Exception {
@ -100,7 +100,7 @@ public class TestBase {
// check userID // check userID
final String userUID = ret.getSubject(); final String userUID = ret.getSubject();
final long id = Long.parseLong(userUID); final long id = Long.parseLong(userUID);
Assertions.assertEquals(0, id); Assertions.assertEquals(1, id);
final String name = (String) ret.getClaim("login"); final String name = (String) ret.getClaim("login");
Assertions.assertEquals("karadmin", name); Assertions.assertEquals("karadmin", name);
@ -119,7 +119,7 @@ public class TestBase {
Assertions.assertEquals(true, applRight.get("USER")); Assertions.assertEquals(true, applRight.get("USER"));
//logger.debug("request user: '{}' right: '{}' row='{}'", userUID, applRight, rowRight); //logger.debug("request user: '{}' right: '{}' row='{}'", userUID, applRight, rowRight);
//Assertions.assertEquals("eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9", splitted[0]); //Assertions.assertEquals("eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9", splitted[0]);
//Assertions.assertEquals("eyJzdWIiOiIwIiwiYXBwbGljYXRpb24iOiJrYXJzbyIsImlzcyI6IkthckF1dGgiLCJyaWdodCI6eyJrYXJzbyI6eyJBRE1JTiI6dHJ1ZSwiVVNFUiI6dHJ1ZX19LCJsb2dpbiI6ImthcmFkbWluIiwiZXhwIjoxNjg0MTk5MTkzLCJpYXQiOjE2ODI3NTU0MjV9", splitted[1]); //Assertions.assertEquals("eyJzdWIiOiIwIiwiYXBwbGljYXRpb24iOiJrYXJzbyIsImlzcyI6IkthckF1dGgiLCJyaWdodCI6eyJrYXJzbyI6eyJBRE1JTiI6dHJ1ZSwiVVNFUiI6dHJ1ZX19LCJsb2dpbiI6ImthcmFkbWluIiwiZXhwIjoxNjg0MTk5MTkzLCJpYXQiOjE2ODI3NTU0MjV9", splitted[1]);
// TODO ... Assertions.assertEquals("????", splitted[2]); // TODO ... Assertions.assertEquals("????", splitted[2]);
@ -151,7 +151,7 @@ public class TestBase {
LOGGER.error("Unexpected throw error: {}", ex); LOGGER.error("Unexpected throw error: {}", ex);
Assertions.fail("Unexpected throws..."); Assertions.fail("Unexpected throws...");
} }
} }
public void checkWork(final String type, final String urlOffset) { public void checkWork(final String type, final String urlOffset) {
@ -177,7 +177,7 @@ public class TestBase {
LOGGER.error("Unexpected throw error: {}", ex); LOGGER.error("Unexpected throw error: {}", ex);
Assertions.fail("Unexpected throws..."); Assertions.fail("Unexpected throws...");
} }
} }
@Order(4) @Order(4)
@ -199,17 +199,17 @@ public class TestBase {
checkFail("GET", "application/small", 401); checkFail("GET", "application/small", 401);
checkFail("GET", "application/get_token", 401); checkFail("GET", "application/get_token", 401);
checkFail("GET", "application/return", 401); checkFail("GET", "application/return", 401);
// /application_token/ section: // /application_token/ section:
checkFail("GET", "application_token/0", 401); checkFail("GET", "application_token/0", 401);
checkFail("DELETE", "application_token/0/5", 401); checkFail("DELETE", "application_token/0/5", 401);
checkFail("DELETE", "application_token/0/create", 401); checkFail("DELETE", "application_token/0/create", 401);
// /front/* // /front/*
checkFail("GET", "front", 404); // no index in test section checkFail("GET", "front", 404); // no index in test section
// health check // health check
checkWork("GET", "health_check"); checkWork("GET", "health_check");
// public_key (only application) // public_key (only application)
checkFail("GET", "public_key", 401); checkFail("GET", "public_key", 401);
checkFail("GET", "public_key/pem", 401); checkFail("GET", "public_key/pem", 401);
@ -220,12 +220,12 @@ public class TestBase {
checkFail("GET", "right/0", 401); checkFail("GET", "right/0", 401);
checkFail("PUT", "right/0", 401, "{}"); checkFail("PUT", "right/0", 401, "{}");
checkFail("DELETE", "right/0", 401); checkFail("DELETE", "right/0", 401);
// /system_config // /system_config
checkWork("GET", "system_config/is_sign_up_availlable"); checkWork("GET", "system_config/is_sign_up_availlable");
checkFail("GET", "system_config/key/skjdfhkjsdhfkjsh", 401); checkFail("GET", "system_config/key/skjdfhkjsdhfkjsh", 401);
checkFail("PUT", "system_config/key/skjdfhkjsdhfkjsh", 401, "{}"); checkFail("PUT", "system_config/key/skjdfhkjsdhfkjsh", 401, "{}");
// /users // /users
checkFail("GET", "users", 401); checkFail("GET", "users", 401);
checkFail("GET", "users/0", 401); checkFail("GET", "users/0", 401);
@ -240,15 +240,15 @@ public class TestBase {
checkWork("GET", "users/check_email?email=admin@admin.ZZZ"); checkWork("GET", "users/check_email?email=admin@admin.ZZZ");
checkFail("GET", "users/check_email?email=ksjhdkjfhskjdh", 404); checkFail("GET", "users/check_email?email=ksjhdkjfhskjdh", 404);
// not testable : get_token // not testable : get_token
} }
@Order(5) @Order(5)
@Test @Test
public void testMeWithToken() throws Exception { public void testMeWithToken() throws Exception {
loginAdmin(); loginAdmin();
final String result = api.get(String.class, "users/me"); final String result = api.get(String.class, "users/me");
Assertions.assertEquals("{\"id\":0,\"login\":\"karadmin\"}", result); Assertions.assertEquals("{\"id\":1,\"login\":\"karadmin\"}", result);
} }