[DEV] update and correct test
This commit is contained in:
parent
00295b94d1
commit
5256278219
@ -44,8 +44,17 @@ public class RightResource {
|
||||
logger.debug("Get some descriptions: {} applicationId={}", rightsDescriptions.size(), applicationId);
|
||||
if (rightsDescriptions != null && rightsDescriptions.size() != 0) {
|
||||
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) {
|
||||
|
||||
if (description == null) {
|
||||
// TODO: this is a really strange case to manage later...
|
||||
continue;
|
||||
|
@ -16,7 +16,7 @@ public class Initialization extends MigrationSqlStep {
|
||||
public String getName() {
|
||||
return "Initialization";
|
||||
}
|
||||
|
||||
|
||||
public Initialization() throws Exception {
|
||||
addClass(Settings.class);
|
||||
addClass(UserAuth.class);
|
||||
@ -44,32 +44,32 @@ public class Initialization extends MigrationSqlStep {
|
||||
('SIGN_UP_ENABLE', 'rwr-r-', 'BOOLEAN', 'false'),
|
||||
('SIGN_IN_ENABLE', 'rwr-r-', 'BOOLEAN', 'true'),
|
||||
('SIGN_UP_FILTER', 'rw----', 'STRING', '.*'),
|
||||
('EMAIL_VALIDATION_REQUIRED', 'rwr-r-', 'BOOLEAN', 'false');
|
||||
('EMAIL_VALIDATION_REQUIRED', 'rwr-r-', 'BOOLEAN', 'false');
|
||||
""");
|
||||
addAction("""
|
||||
INSERT INTO `rightDescription` (`id`, `applicationId`, `key`, `title`, `description`, `type`) VALUES
|
||||
(1, 1, 'ADMIN', 'Administrator', 'Full administrator Right', 'BOOLEAN');
|
||||
INSERT INTO `rightDescription` (`id`, `applicationId`, `key`, `title`, `description`, `type`, `defaultValue`) VALUES
|
||||
(1, 1, 'ADMIN', 'Administrator', 'Full administrator Right', 'BOOLEAN', 'false');
|
||||
""");
|
||||
addAction("""
|
||||
INSERT INTO `right` (`applicationId`, `userId`, `rightDescriptionId`, `value`) VALUES
|
||||
(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("""
|
||||
ALTER TABLE `application` AUTO_INCREMENT = 1000;
|
||||
""");
|
||||
""", "mysql");
|
||||
addAction("""
|
||||
ALTER TABLE `user` AUTO_INCREMENT = 1000;
|
||||
""");
|
||||
""", "mysql");
|
||||
addAction("""
|
||||
ALTER TABLE `settings` AUTO_INCREMENT = 1000;
|
||||
""");
|
||||
""", "mysql");
|
||||
addAction("""
|
||||
ALTER TABLE `right` AUTO_INCREMENT = 1000;
|
||||
""");
|
||||
""", "mysql");
|
||||
addAction("""
|
||||
ALTER TABLE `rightDescription` AUTO_INCREMENT = 1000;
|
||||
""");
|
||||
""", "mysql");
|
||||
display();
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ import com.nimbusds.jwt.JWTClaimsSet;
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
public class TestBase {
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(TestBase.class);
|
||||
|
||||
|
||||
static WebLauncherTest webInterface = null;
|
||||
static RESTApi api = null;
|
||||
|
||||
@ -42,11 +42,11 @@ public class TestBase {
|
||||
Assertions.fail("Can not get Authentication for '" + login + "' ==> " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void loginAdmin() {
|
||||
login("karadmin", "adminA@666");
|
||||
}
|
||||
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
LOGGER.info("configure server ...");
|
||||
@ -70,7 +70,7 @@ public class TestBase {
|
||||
webInterface = null;
|
||||
// TODO: do it better...
|
||||
}
|
||||
|
||||
|
||||
@Order(1)
|
||||
@Test
|
||||
//@RepeatedTest(10)
|
||||
@ -78,13 +78,13 @@ public class TestBase {
|
||||
final HealthResult result = api.get(HealthResult.class, "health_check");
|
||||
Assertions.assertEquals(result.value(), "alive and kicking");
|
||||
}
|
||||
|
||||
|
||||
@Order(2)
|
||||
@Test
|
||||
public void checkHealthCheckWrongAPI() throws Exception {
|
||||
Assertions.assertThrows(RESTErrorResponseExeption.class, () -> api.get(HealthResult.class, "health_checks"));
|
||||
}
|
||||
|
||||
|
||||
@Order(3)
|
||||
@Test
|
||||
public void firstUserConnect() throws Exception {
|
||||
@ -100,7 +100,7 @@ public class TestBase {
|
||||
// check userID
|
||||
final String userUID = ret.getSubject();
|
||||
final long id = Long.parseLong(userUID);
|
||||
Assertions.assertEquals(0, id);
|
||||
Assertions.assertEquals(1, id);
|
||||
final String name = (String) ret.getClaim("login");
|
||||
Assertions.assertEquals("karadmin", name);
|
||||
|
||||
@ -119,7 +119,7 @@ public class TestBase {
|
||||
Assertions.assertEquals(true, applRight.get("USER"));
|
||||
|
||||
//logger.debug("request user: '{}' right: '{}' row='{}'", userUID, applRight, rowRight);
|
||||
|
||||
|
||||
//Assertions.assertEquals("eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9", splitted[0]);
|
||||
//Assertions.assertEquals("eyJzdWIiOiIwIiwiYXBwbGljYXRpb24iOiJrYXJzbyIsImlzcyI6IkthckF1dGgiLCJyaWdodCI6eyJrYXJzbyI6eyJBRE1JTiI6dHJ1ZSwiVVNFUiI6dHJ1ZX19LCJsb2dpbiI6ImthcmFkbWluIiwiZXhwIjoxNjg0MTk5MTkzLCJpYXQiOjE2ODI3NTU0MjV9", splitted[1]);
|
||||
// TODO ... Assertions.assertEquals("????", splitted[2]);
|
||||
@ -151,7 +151,7 @@ public class TestBase {
|
||||
LOGGER.error("Unexpected throw error: {}", ex);
|
||||
Assertions.fail("Unexpected throws...");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void checkWork(final String type, final String urlOffset) {
|
||||
@ -177,7 +177,7 @@ public class TestBase {
|
||||
LOGGER.error("Unexpected throw error: {}", ex);
|
||||
Assertions.fail("Unexpected throws...");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Order(4)
|
||||
@ -199,17 +199,17 @@ public class TestBase {
|
||||
checkFail("GET", "application/small", 401);
|
||||
checkFail("GET", "application/get_token", 401);
|
||||
checkFail("GET", "application/return", 401);
|
||||
|
||||
|
||||
// /application_token/ section:
|
||||
checkFail("GET", "application_token/0", 401);
|
||||
checkFail("DELETE", "application_token/0/5", 401);
|
||||
checkFail("DELETE", "application_token/0/create", 401);
|
||||
|
||||
|
||||
// /front/*
|
||||
checkFail("GET", "front", 404); // no index in test section
|
||||
// health check
|
||||
checkWork("GET", "health_check");
|
||||
|
||||
|
||||
// public_key (only application)
|
||||
checkFail("GET", "public_key", 401);
|
||||
checkFail("GET", "public_key/pem", 401);
|
||||
@ -220,12 +220,12 @@ public class TestBase {
|
||||
checkFail("GET", "right/0", 401);
|
||||
checkFail("PUT", "right/0", 401, "{}");
|
||||
checkFail("DELETE", "right/0", 401);
|
||||
|
||||
|
||||
// /system_config
|
||||
checkWork("GET", "system_config/is_sign_up_availlable");
|
||||
checkFail("GET", "system_config/key/skjdfhkjsdhfkjsh", 401);
|
||||
checkFail("PUT", "system_config/key/skjdfhkjsdhfkjsh", 401, "{}");
|
||||
|
||||
|
||||
// /users
|
||||
checkFail("GET", "users", 401);
|
||||
checkFail("GET", "users/0", 401);
|
||||
@ -240,15 +240,15 @@ public class TestBase {
|
||||
checkWork("GET", "users/check_email?email=admin@admin.ZZZ");
|
||||
checkFail("GET", "users/check_email?email=ksjhdkjfhskjdh", 404);
|
||||
// not testable : get_token
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Order(5)
|
||||
@Test
|
||||
public void testMeWithToken() throws Exception {
|
||||
loginAdmin();
|
||||
final String result = api.get(String.class, "users/me");
|
||||
Assertions.assertEquals("{\"id\":0,\"login\":\"karadmin\"}", result);
|
||||
Assertions.assertEquals("{\"id\":1,\"login\":\"karadmin\"}", result);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user