Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cleanup publication api #284

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ 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)$");
private static final Pattern RESOURCE_OPERATIONS = Pattern.compile("^/v1/ops/resource/(move)$");

private static final Pattern DEPLOYMENT_LIMITS = Pattern.compile("^/v1/deployments/([^/]+)/limits$");

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
20 changes: 10 additions & 10 deletions src/test/java/com/epam/aidial/core/ResourceOperationApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void testMoveResourceWorkflow() {
verifyJson(response, 200, CONVERSATION_BODY_1);

// verify move operation
response = send(HttpMethod.POST, "/v1/ops/resources/move", null, """
response = send(HttpMethod.POST, "/v1/ops/resource/move", null, """
{
"sourceUrl": "conversations/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/folder/conversation",
"destinationUrl": "conversations/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/folder2/conversation2"
Expand Down Expand Up @@ -54,7 +54,7 @@ void testMoveResourceWorkflowWhenDestinationResourceExists() {
verifyJson(response, 200, CONVERSATION_BODY_2);

// verify move operation
response = send(HttpMethod.POST, "/v1/ops/resources/move", null, """
response = send(HttpMethod.POST, "/v1/ops/resource/move", null, """
{
"sourceUrl": "conversations/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/folder/conversation",
"destinationUrl": "conversations/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/folder2/conversation2"
Expand All @@ -69,7 +69,7 @@ void testMoveResourceWorkflowWhenDestinationResourceExists() {
response = resourceRequest(HttpMethod.GET, "/folder2/conversation2");
verifyJson(response, 200, CONVERSATION_BODY_2);

response = send(HttpMethod.POST, "/v1/ops/resources/move", null, """
response = send(HttpMethod.POST, "/v1/ops/resource/move", null, """
{
"sourceUrl": "conversations/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/folder/conversation",
"destinationUrl": "conversations/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/folder2/conversation2",
Expand Down Expand Up @@ -124,7 +124,7 @@ void testMoveOperationCopySharedAccess() {
verify(response, 200, CONVERSATION_BODY_1);

// verify move operation
response = send(HttpMethod.POST, "/v1/ops/resources/move", null, """
response = send(HttpMethod.POST, "/v1/ops/resource/move", null, """
{
"sourceUrl": "conversations/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/folder/conversation",
"destinationUrl": "conversations/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/folder2/conversation2"
Expand Down Expand Up @@ -210,23 +210,23 @@ void testMoveOperationCopySharedAccess() {
@Test
void testMoveOperationErrors() {
// verify sourceUrl must be present
Response response = send(HttpMethod.POST, "/v1/ops/resources/move", null, """
Response response = send(HttpMethod.POST, "/v1/ops/resource/move", null, """
{
"destinationUrl": "conversations/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/folder2/conversation2"
}
""");
verify(response, 400);

// verify destinationUrl must be present
response = send(HttpMethod.POST, "/v1/ops/resources/move", null, """
response = send(HttpMethod.POST, "/v1/ops/resource/move", null, """
{
"sourceUrl": "conversations/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/folder/conversation"
}
""");
verify(response, 400);

// verify source and dest must be the same type
response = send(HttpMethod.POST, "/v1/ops/resources/move", null, """
response = send(HttpMethod.POST, "/v1/ops/resource/move", null, """
{
"sourceUrl": "conversations/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/folder/conversation",
"destinationUrl": "files/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/folder2/conversation2"
Expand All @@ -235,7 +235,7 @@ void testMoveOperationErrors() {
verify(response, 400);

// verify source must belong to the user
response = send(HttpMethod.POST, "/v1/ops/resources/move", null, """
response = send(HttpMethod.POST, "/v1/ops/resource/move", null, """
{
"sourceUrl": "conversations/7G9WZNcoY26Vy9D7bEgbv6zqbJGfyDp9KZyEbJR4XMZt/folder/conversation",
"destinationUrl": "conversations/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/folder2/conversation2"
Expand All @@ -244,7 +244,7 @@ void testMoveOperationErrors() {
verify(response, 400);

// verify move do not support folders
response = send(HttpMethod.POST, "/v1/ops/resources/move", null, """
response = send(HttpMethod.POST, "/v1/ops/resource/move", null, """
{
"sourceUrl": "conversations/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/folder/",
"destinationUrl": "files/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/folder2/conversation2"
Expand All @@ -253,7 +253,7 @@ void testMoveOperationErrors() {
verify(response, 400);

// verify sourceUrl do not exists
response = send(HttpMethod.POST, "/v1/ops/resources/move", null, """
response = send(HttpMethod.POST, "/v1/ops/resource/move", null, """
{
"sourceUrl": "conversations/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/folder/conversation",
"destinationUrl": "files/3CcedGxCx23EwiVbVmscVktScRyf46KypuBQ65miviST/folder2/conversation2"
Expand Down
Loading