Skip to content

Commit

Permalink
cleanup publication api
Browse files Browse the repository at this point in the history
  • Loading branch information
artsiomkorzun committed Mar 15, 2024
1 parent b3750b5 commit 304e5f0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public class ControllerSelector {
private static final Pattern SHARE_RESOURCE_OPERATIONS = Pattern.compile("^/v1/ops/resource/share/(create|list|discard|revoke|copy)$");
private static final Pattern INVITATIONS = Pattern.compile("^/v1/invitations$");
private static final Pattern INVITATION = Pattern.compile("^/v1/invitations/([a-zA-Z0-9]+)$");
private static final Pattern PUBLICATIONS = Pattern.compile("^/v1/ops/publications/(list|get|create|delete|approve|reject)$");
private static final Pattern PUBLICATION_RULES = Pattern.compile("^/v1/ops/publications/rules/list$");
private static final Pattern PUBLICATIONS = Pattern.compile("^/v1/ops/publication/(list|get|create|delete|approve|reject)$");
private static final Pattern PUBLICATION_RULES = Pattern.compile("^/v1/ops/publication/rule/list$");

private static final Pattern RESOURCE_OPERATIONS = Pattern.compile("^/v1/ops/resources/(move)$");

Expand Down
78 changes: 39 additions & 39 deletions src/test/java/com/epam/aidial/core/PublicationApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,21 @@ void testPublicationCreation() {
Response response = resourceRequest(HttpMethod.PUT, "/my/folder/conversation", CONVERSATION_BODY_1);
verify(response, 200);

response = operationRequest("/v1/ops/publications/create", PUBLICATION_REQUEST.formatted(bucket, bucket));
response = operationRequest("/v1/ops/publication/create", PUBLICATION_REQUEST.formatted(bucket, bucket));
verifyJson(response, 200, PUBLICATION_RESPONSE);


response = operationRequest("/v1/ops/publications/get", PUBLICATION_URL);
response = operationRequest("/v1/ops/publication/get", PUBLICATION_URL);
verifyJson(response, 200, PUBLICATION_RESPONSE);

response = operationRequest("/v1/ops/publications/get", PUBLICATION_URL, "authorization", "admin");
response = operationRequest("/v1/ops/publication/get", PUBLICATION_URL, "authorization", "admin");
verifyJson(response, 200, PUBLICATION_RESPONSE);

response = operationRequest("/v1/ops/publications/get", PUBLICATION_URL, "authorization", "user");
response = operationRequest("/v1/ops/publication/get", PUBLICATION_URL, "authorization", "user");
verify(response, 403);


response = operationRequest("/v1/ops/publications/list", """
response = operationRequest("/v1/ops/publication/list", """
{
"url": "publications/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/"
}
Expand Down Expand Up @@ -112,14 +112,14 @@ void testPublicationDeletion() {
Response response = resourceRequest(HttpMethod.PUT, "/my/folder/conversation", CONVERSATION_BODY_1);
verify(response, 200);

response = operationRequest("/v1/ops/publications/create", PUBLICATION_REQUEST.formatted(bucket, bucket));
response = operationRequest("/v1/ops/publication/create", PUBLICATION_REQUEST.formatted(bucket, bucket));
verify(response, 200);


response = operationRequest("/v1/ops/publications/delete", PUBLICATION_URL, "authorization", "user");
response = operationRequest("/v1/ops/publication/delete", PUBLICATION_URL, "authorization", "user");
verify(response, 403);

response = operationRequest("/v1/ops/publications/delete", PUBLICATION_URL);
response = operationRequest("/v1/ops/publication/delete", PUBLICATION_URL);
verify(response, 200);


Expand All @@ -138,17 +138,17 @@ void testPublicationApprove() {
Response response = resourceRequest(HttpMethod.PUT, "/my/folder/conversation", CONVERSATION_BODY_1);
verify(response, 200);

response = operationRequest("/v1/ops/publications/create", PUBLICATION_REQUEST.formatted(bucket, bucket));
response = operationRequest("/v1/ops/publication/create", PUBLICATION_REQUEST.formatted(bucket, bucket));
verify(response, 200);


response = operationRequest("/v1/ops/publications/approve", PUBLICATION_URL);
response = operationRequest("/v1/ops/publication/approve", PUBLICATION_URL);
verify(response, 403);

response = operationRequest("/v1/ops/publications/approve", PUBLICATION_URL, "authorization", "user");
response = operationRequest("/v1/ops/publication/approve", PUBLICATION_URL, "authorization", "user");
verify(response, 403);

response = operationRequest("/v1/ops/publications/approve", PUBLICATION_URL, "authorization", "admin");
response = operationRequest("/v1/ops/publication/approve", PUBLICATION_URL, "authorization", "admin");
verifyJson(response, 200, """
{
"url" : "publications/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/0123",
Expand Down Expand Up @@ -207,17 +207,17 @@ void testPublicationReject() {
Response response = resourceRequest(HttpMethod.PUT, "/my/folder/conversation", CONVERSATION_BODY_1);
verify(response, 200);

response = operationRequest("/v1/ops/publications/create", PUBLICATION_REQUEST.formatted(bucket, bucket));
response = operationRequest("/v1/ops/publication/create", PUBLICATION_REQUEST.formatted(bucket, bucket));
verify(response, 200);


response = operationRequest("/v1/ops/publications/reject", PUBLICATION_URL);
response = operationRequest("/v1/ops/publication/reject", PUBLICATION_URL);
verify(response, 403);

response = operationRequest("/v1/ops/publications/reject", PUBLICATION_URL, "authorization", "user");
response = operationRequest("/v1/ops/publication/reject", PUBLICATION_URL, "authorization", "user");
verify(response, 403);

response = operationRequest("/v1/ops/publications/reject", PUBLICATION_URL, "authorization", "admin");
response = operationRequest("/v1/ops/publication/reject", PUBLICATION_URL, "authorization", "admin");
verifyJson(response, 200, """
{
"url" : "publications/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/0123",
Expand Down Expand Up @@ -291,7 +291,7 @@ void testResourceList() {
verify(response, 200);


response = operationRequest("/v1/ops/publications/create", """
response = operationRequest("/v1/ops/publication/create", """
{
"url": "publications/%s/",
"targetUrl": "public/folder1/",
Expand All @@ -312,13 +312,13 @@ void testResourceList() {
""".formatted(bucket, bucket));
verify(response, 200);

response = operationRequest("/v1/ops/publications/approve", """
response = operationRequest("/v1/ops/publication/approve", """
{"url": "publications/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/0123"}
""", "authorization", "admin");
verify(response, 200);


response = operationRequest("/v1/ops/publications/create", """
response = operationRequest("/v1/ops/publication/create", """
{
"url": "publications/%s/",
"targetUrl": "public/folder2/",
Expand All @@ -339,7 +339,7 @@ void testResourceList() {
""".formatted(bucket, bucket));
verify(response, 200);

response = operationRequest("/v1/ops/publications/approve", """
response = operationRequest("/v1/ops/publication/approve", """
{"url": "publications/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/0124"}
""", "authorization", "admin");
verify(response, 200);
Expand Down Expand Up @@ -453,17 +453,17 @@ void testResourceList() {

@Test
void testPublicationList() {
Response response = operationRequest("/v1/ops/publications/list", """
Response response = operationRequest("/v1/ops/publication/list", """
{"url": "publications/public/"}
""");
verify(response, 403);

response = operationRequest("/v1/ops/publications/list", """
response = operationRequest("/v1/ops/publication/list", """
{"url": "publications/public/"}
""", "authorization", "user");
verify(response, 403);

response = operationRequest("/v1/ops/publications/list", """
response = operationRequest("/v1/ops/publication/list", """
{"url": "publications/public/"}
""", "authorization", "admin");
verifyJson(response, 200, """
Expand All @@ -476,21 +476,21 @@ void testPublicationList() {
response = resourceRequest(HttpMethod.PUT, "/my/folder/conversation", CONVERSATION_BODY_1);
verify(response, 200);

response = operationRequest("/v1/ops/publications/create", PUBLICATION_REQUEST.formatted(bucket, bucket));
response = operationRequest("/v1/ops/publication/create", PUBLICATION_REQUEST.formatted(bucket, bucket));
verify(response, 200);


response = operationRequest("/v1/ops/publications/list", """
response = operationRequest("/v1/ops/publication/list", """
{"url": "publications/public/"}
""");
verify(response, 403);

response = operationRequest("/v1/ops/publications/list", """
response = operationRequest("/v1/ops/publication/list", """
{"url": "publications/public/"}
""", "authorization", "user");
verify(response, 403);

response = operationRequest("/v1/ops/publications/list", """
response = operationRequest("/v1/ops/publication/list", """
{"url": "publications/public/"}
""", "authorization", "admin");
verifyJson(response, 200, """
Expand All @@ -505,11 +505,11 @@ void testPublicationList() {
""");


response = operationRequest("/v1/ops/publications/approve", PUBLICATION_URL, "authorization", "admin");
response = operationRequest("/v1/ops/publication/approve", PUBLICATION_URL, "authorization", "admin");
verify(response, 200);


response = operationRequest("/v1/ops/publications/list", """
response = operationRequest("/v1/ops/publication/list", """
{"url": "publications/public/"}
""", "authorization", "admin");
verifyJson(response, 200, """
Expand All @@ -521,17 +521,17 @@ void testPublicationList() {

@Test
void listRules() {
Response response = operationRequest("/v1/ops/publications/rules/list", """
Response response = operationRequest("/v1/ops/publication/rule/list", """
{"url": ""}
""");
verify(response, 400);

response = operationRequest("/v1/ops/publications/rules/list", """
response = operationRequest("/v1/ops/publication/rule/list", """
{"url": "public"}
""");
verify(response, 400);

response = operationRequest("/v1/ops/publications/rules/list", """
response = operationRequest("/v1/ops/publication/rule/list", """
{"url": "public/"}
""");
verifyJson(response, 200, """
Expand All @@ -540,7 +540,7 @@ void listRules() {
}
""");

response = operationRequest("/v1/ops/publications/rules/list", """
response = operationRequest("/v1/ops/publication/rule/list", """
{"url": "public/"}
""", "authorization", "user");
verifyJson(response, 200, """
Expand All @@ -549,7 +549,7 @@ void listRules() {
}
""");

response = operationRequest("/v1/ops/publications/rules/list", """
response = operationRequest("/v1/ops/publication/rule/list", """
{"url": "public/"}
""", "authorization", "admin");
verifyJson(response, 200, """
Expand All @@ -561,14 +561,14 @@ void listRules() {
response = resourceRequest(HttpMethod.PUT, "/my/folder/conversation", CONVERSATION_BODY_1);
verify(response, 200);

response = operationRequest("/v1/ops/publications/create", PUBLICATION_REQUEST.formatted(bucket, bucket));
response = operationRequest("/v1/ops/publication/create", PUBLICATION_REQUEST.formatted(bucket, bucket));
verify(response, 200);

response = operationRequest("/v1/ops/publications/approve", PUBLICATION_URL, "authorization", "admin");
response = operationRequest("/v1/ops/publication/approve", PUBLICATION_URL, "authorization", "admin");
verify(response, 200);


response = operationRequest("/v1/ops/publications/rules/list", """
response = operationRequest("/v1/ops/publication/rule/list", """
{"url": "public/folder/"}
""", "authorization", "user");
verifyJson(response, 200, """
Expand All @@ -583,7 +583,7 @@ void listRules() {
}
""");

response = operationRequest("/v1/ops/publications/rules/list", """
response = operationRequest("/v1/ops/publication/rule/list", """
{"url": "public/folder/"}
""", "authorization", "admin");
verifyJson(response, 200, """
Expand All @@ -598,7 +598,7 @@ void listRules() {
}
""");

response = operationRequest("/v1/ops/publications/rules/list", """
response = operationRequest("/v1/ops/publication/rule/list", """
{"url": "public/folder/"}
""");
verify(response, 403);
Expand Down

0 comments on commit 304e5f0

Please sign in to comment.