SHA256
30 03 25
Добавил АПИ функцию которая возвращает информацию о версии сервера и о том что он работает
This commit is contained in:
@@ -1,3 +1,14 @@
|
||||
server.1port=7070
|
||||
db.path=data/shine.sqlite
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Server public info
|
||||
# Эти поля используются JSON-операцией GetServerInfo.
|
||||
# Если какое-то значение не задано, сервер вернёт пустую строку.
|
||||
# ------------------------------------------------------------
|
||||
server.version=${projectVersion}
|
||||
server.info.url=
|
||||
server.info.physicalRegion=
|
||||
server.info.description=
|
||||
server.info.origin=
|
||||
server.info.extraInfo=
|
||||
|
||||
@@ -36,6 +36,8 @@ public class IT_01_AddUser {
|
||||
|
||||
try (WsSession ws = WsSession.open()) {
|
||||
|
||||
checkPingAndServerInfo(r, ws, t);
|
||||
|
||||
r.ok("AddUser USER1: " + TestConfig.LOGIN());
|
||||
String resp1 = ws.call("AddUser#USER1", JsonBuilders.addUser(TestConfig.LOGIN()), t);
|
||||
checkAddUser200or409(r, resp1);
|
||||
@@ -76,6 +78,38 @@ public class IT_01_AddUser {
|
||||
return r.summaryLine();
|
||||
}
|
||||
|
||||
private static void checkPingAndServerInfo(TestResult r, WsSession ws, Duration t) {
|
||||
String pingResp = ws.call("Ping", JsonBuilders.ping(System.currentTimeMillis()), t);
|
||||
if (JsonParsers.status(pingResp) != 200 || !Boolean.TRUE.equals(JsonParsers.ok(pingResp))) {
|
||||
r.fail("Ping: ожидали status=200 и ok=true, resp=" + pingResp);
|
||||
fail("Ping unexpected response");
|
||||
}
|
||||
|
||||
Long serverTs = JsonParsers.pingTs(pingResp);
|
||||
if (serverTs == null || serverTs <= 0) {
|
||||
r.fail("Ping: сервер не вернул ts, resp=" + pingResp);
|
||||
fail("Ping missing ts");
|
||||
}
|
||||
r.ok("Ping: ok, serverTs=" + serverTs);
|
||||
|
||||
String infoResp = ws.call("GetServerInfo", JsonBuilders.getServerInfo(), t);
|
||||
if (JsonParsers.status(infoResp) != 200 || !Boolean.TRUE.equals(JsonParsers.ok(infoResp))) {
|
||||
r.fail("GetServerInfo: ожидали status=200 и ok=true, resp=" + infoResp);
|
||||
fail("GetServerInfo unexpected response");
|
||||
}
|
||||
if (!JsonParsers.payloadIsObject(infoResp)) {
|
||||
r.fail("GetServerInfo: payload должен быть объектом, resp=" + infoResp);
|
||||
fail("GetServerInfo payload is not object");
|
||||
}
|
||||
|
||||
r.ok("GetServerInfo: ok, url='" + safe(JsonParsers.payloadText(infoResp, "url"))
|
||||
+ "', version='" + safe(JsonParsers.payloadText(infoResp, "version"))
|
||||
+ "', physicalRegion='" + safe(JsonParsers.payloadText(infoResp, "physicalRegion"))
|
||||
+ "', description='" + safe(JsonParsers.payloadText(infoResp, "description"))
|
||||
+ "', origin='" + safe(JsonParsers.payloadText(infoResp, "origin"))
|
||||
+ "', extraInfo='" + safe(JsonParsers.payloadText(infoResp, "extraInfo")) + "'");
|
||||
}
|
||||
|
||||
private static void checkAddUser200or409(TestResult r, String resp) {
|
||||
int st = JsonParsers.status(resp);
|
||||
if (st == 200) {
|
||||
@@ -324,4 +358,8 @@ public class IT_01_AddUser {
|
||||
private static boolean isBlank(String s) {
|
||||
return s == null || s.trim().isEmpty();
|
||||
}
|
||||
|
||||
private static String safe(String s) {
|
||||
return s == null ? "" : s;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package test.it.runner;
|
||||
|
||||
import test.it.cases.IT_01_AddUser;
|
||||
import test.it.cases.IT_00_TechnicalRequests;
|
||||
import test.it.cases.IT_02_Sessions;
|
||||
import test.it.cases.IT_03_AddBlock_NoAuth;
|
||||
import test.it.cases.IT_04_UserParams_NoAuth;
|
||||
@@ -37,6 +38,9 @@ public class IT_RunAllMain {
|
||||
TestLog.title("IT RUN: запуск всех тестов подряд"
|
||||
+ (STOP_ON_FIRST_FAIL ? " (STOP_ON_FIRST_FAIL=ON)" : " (STOP_ON_FIRST_FAIL=OFF)"));
|
||||
|
||||
String s0 = IT_00_TechnicalRequests.run(); summaries.add(s0);
|
||||
if (s0.contains("FAIL:")) { failed++; if (STOP_ON_FIRST_FAIL) return finishEarly(summaries, failed); }
|
||||
|
||||
String s1 = IT_01_AddUser.run(); summaries.add(s1);
|
||||
if (s1.contains("FAIL:")) { failed++; if (STOP_ON_FIRST_FAIL) return finishEarly(summaries, failed); }
|
||||
|
||||
@@ -69,4 +73,4 @@ public class IT_RunAllMain {
|
||||
|
||||
return failed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,6 +90,35 @@ public final class JsonBuilders {
|
||||
""".formatted(requestId, login);
|
||||
}
|
||||
|
||||
// ---------------- Ping ----------------
|
||||
|
||||
public static String ping(long ts) {
|
||||
String requestId = TestIds.next("ping");
|
||||
return """
|
||||
{
|
||||
"op": "Ping",
|
||||
"requestId": "%s",
|
||||
"payload": {
|
||||
"ts": %d
|
||||
}
|
||||
}
|
||||
""".formatted(requestId, ts);
|
||||
}
|
||||
|
||||
// ---------------- GetServerInfo ----------------
|
||||
|
||||
public static String getServerInfo() {
|
||||
String requestId = TestIds.next("serverinfo");
|
||||
return """
|
||||
{
|
||||
"op": "GetServerInfo",
|
||||
"requestId": "%s",
|
||||
"payload": {
|
||||
}
|
||||
}
|
||||
""".formatted(requestId);
|
||||
}
|
||||
|
||||
// ---------------- AuthChallenge ----------------
|
||||
|
||||
public static String authChallenge(String login) {
|
||||
|
||||
@@ -132,6 +132,21 @@ public final class JsonParsers {
|
||||
}
|
||||
}
|
||||
|
||||
public static Long pingTs(String json) {
|
||||
try {
|
||||
JsonNode root = MAPPER.readTree(json);
|
||||
JsonNode payload = root.get("payload");
|
||||
if (payload != null && payload.has("ts")) return payload.get("ts").asLong();
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String payloadText(String json, String field) {
|
||||
return getPayloadText(json, field);
|
||||
}
|
||||
|
||||
public static List<String> sessionIds(String json) {
|
||||
List<String> res = new ArrayList<>();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user