mirror of
https://github.com/Alfresco/SearchServices.git
synced 2026-09-16 18:12:56 +00:00
Added tests for authentication endpoints.
This commit is contained in:
@@ -1,18 +1,31 @@
|
||||
package org.alfresco.rest.auth;
|
||||
|
||||
import org.alfresco.rest.RestTest;
|
||||
import org.alfresco.rest.core.RestWrapper;
|
||||
import org.alfresco.rest.exception.JsonToModelConversionException;
|
||||
import org.alfresco.rest.model.RestTicketBodyModel;
|
||||
import org.alfresco.rest.model.RestTicketModel;
|
||||
import org.alfresco.utility.model.TestGroup;
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
import org.alfresco.utility.testrail.ExecutionType;
|
||||
import org.alfresco.utility.testrail.annotation.TestRail;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class AuthTests extends RestTest
|
||||
{
|
||||
@TestRail(section = { TestGroup.REST_API, TestGroup.AUTH }, executionType = ExecutionType.SANITY, description = "Verify TICKET is returned on admin user")
|
||||
|
||||
private RestWrapper addRestRequestAuthorization(RestTicketModel ticketModel)
|
||||
{
|
||||
restClient.configureRequestSpec().addHeader("Authorization", "Basic " + encodeB64(ticketModel.getId()));
|
||||
return restClient;
|
||||
}
|
||||
|
||||
@TestRail(section = { TestGroup.REST_API,
|
||||
TestGroup.AUTH }, executionType = ExecutionType.SANITY, description = "Verify HttpMethod.POST tickets")
|
||||
@Test(groups = { TestGroup.REST_API, TestGroup.SANITY, TestGroup.AUTH })
|
||||
public void adminShouldGetTicketBody() throws JsonToModelConversionException, Exception
|
||||
{
|
||||
@@ -26,4 +39,50 @@ public class AuthTests extends RestTest
|
||||
ticketReturned.assertThat().field("id").contains("TICKET_");
|
||||
}
|
||||
|
||||
@TestRail(section = { TestGroup.REST_API,
|
||||
TestGroup.AUTH }, executionType = ExecutionType.SANITY, description = "Verify HttpMethod.GET tickets/-me-")
|
||||
@Test(groups = { TestGroup.REST_API, TestGroup.SANITY, TestGroup.AUTH })
|
||||
public void randomUserGetTicket() throws Exception
|
||||
{
|
||||
UserModel userModel = dataUser.createRandomTestUser();
|
||||
RestTicketBodyModel ticketBody = new RestTicketBodyModel();
|
||||
ticketBody.setUserId(userModel.getUsername());
|
||||
ticketBody.setPassword(userModel.getPassword());
|
||||
|
||||
RestTicketModel ticketCreated = restClient.authenticateUser(userModel).withAuthAPI().createTicket(ticketBody);
|
||||
restClient.assertStatusCodeIs(HttpStatus.CREATED);
|
||||
|
||||
addRestRequestAuthorization(ticketCreated);
|
||||
RestTicketModel ticketReturned = restClient.withAuthAPI().getTicket();
|
||||
Assert.assertEquals(ticketCreated.getId(), ticketReturned.getId());
|
||||
|
||||
}
|
||||
|
||||
@TestRail(section = { TestGroup.REST_API,
|
||||
TestGroup.AUTH }, executionType = ExecutionType.SANITY, description = "Verify HttpMethod.REMOVE tickets/-me-")
|
||||
@Test(groups = { TestGroup.REST_API, TestGroup.SANITY, TestGroup.AUTH })
|
||||
public void randomUserRemoveTicket() throws Exception
|
||||
{
|
||||
UserModel userModel = dataUser.createRandomTestUser();
|
||||
RestTicketBodyModel ticketBody = new RestTicketBodyModel();
|
||||
ticketBody.setUserId(userModel.getUsername());
|
||||
ticketBody.setPassword(userModel.getPassword());
|
||||
|
||||
RestTicketModel ticketCreated = restClient.authenticateUser(userModel).withAuthAPI().createTicket(ticketBody);
|
||||
restClient.assertStatusCodeIs(HttpStatus.CREATED);
|
||||
|
||||
addRestRequestAuthorization(ticketCreated);
|
||||
restClient.withAuthAPI().removeTicket();
|
||||
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
|
||||
|
||||
restClient.withAuthAPI().getTicket();
|
||||
restClient.assertLastError().containsErrorKey("Ticket base authentication required.");
|
||||
|
||||
}
|
||||
|
||||
private String encodeB64(String str)
|
||||
{
|
||||
return Base64.encodeBase64String(str.getBytes());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user