use of org.jboss.resteasy.mock.MockHttpRequest in project candlepin by candlepin.
the class CloudRegistrationAuthTest method testGetPrincipalAbortsIfAuthenticationIsWrongType.
@Test
public void testGetPrincipalAbortsIfAuthenticationIsWrongType() {
CloudRegistrationInfo cloudRegInfo = this.buildCloudRegistrationInfo("test_type", "metadata", "sig");
CloudRegistrationAuth provider = this.buildAuthProvider();
String token = provider.generateRegistrationToken(mock(Principal.class), cloudRegInfo);
MockHttpRequest request = this.buildHttpRequest();
request.header("Authorization", "Potato " + token);
Principal principal = provider.getPrincipal(request);
assertNull(principal);
}
use of org.jboss.resteasy.mock.MockHttpRequest in project candlepin by candlepin.
the class CloudRegistrationAuthTest method testGetPrincipalIgnoresExpiredTokens.
@Test
public void testGetPrincipalIgnoresExpiredTokens() {
int ctSeconds = this.getCurrentSeconds();
String token = this.buildMalformedToken(new JsonWebToken().type(TOKEN_TYPE).subject("test_subject").audience("test_org").issuedAt(ctSeconds - 15).notBefore(ctSeconds - 15).expiration(ctSeconds - 10));
MockHttpRequest request = this.buildHttpRequest();
request.header("Authorization", "Bearer " + token);
Principal principal = this.buildAuthProvider().getPrincipal(request);
assertNull(principal);
}
use of org.jboss.resteasy.mock.MockHttpRequest in project candlepin by candlepin.
the class CloudRegistrationAuthTest method testGetPrincipalIgnoresInactiveTokens.
@Test
public void testGetPrincipalIgnoresInactiveTokens() {
int ctSeconds = this.getCurrentSeconds();
String token = this.buildMalformedToken(new JsonWebToken().type(TOKEN_TYPE).subject("test_subject").audience("test_org").issuedAt(ctSeconds + 15).notBefore(ctSeconds + 15).expiration(ctSeconds + 25));
MockHttpRequest request = this.buildHttpRequest();
request.header("Authorization", "Bearer " + token);
Principal principal = this.buildAuthProvider().getPrincipal(request);
assertNull(principal);
}
use of org.jboss.resteasy.mock.MockHttpRequest in project candlepin by candlepin.
the class CloudRegistrationAuthTest method testGetPrincipal.
@Test
public void testGetPrincipal() {
CloudRegistrationInfo cloudRegInfo = this.buildCloudRegistrationInfo("test_type", "metadata", "sig");
CloudRegistrationAuth provider = this.buildAuthProvider();
String token = provider.generateRegistrationToken(mock(Principal.class), cloudRegInfo);
MockHttpRequest request = this.buildHttpRequest();
request.header("Authorization", "Bearer " + token);
Principal principal = provider.getPrincipal(request);
assertNotNull(principal);
assertTrue(principal instanceof UserPrincipal);
// Test note:
// The owner key resolves to the cloud registration type due to the mock adapter implementation
// we've defined in our test init, which *always* uses the type as the owner key. In the real
// implementation, this isn't guaranteed.
String ownerKey = cloudRegInfo.getType();
Owner owner = this.mockOwnerCurator.getByKey(ownerKey);
assertTrue(principal.canAccess(owner, SubResource.CONSUMERS, Access.CREATE));
}
use of org.jboss.resteasy.mock.MockHttpRequest in project scm-review-plugin by scm-manager.
the class CommentRootResourceTest method shouldNotThrowConflictExceptionIfNoExpectationsInUrl.
@Test
@SubjectAware(username = "slarti", password = "secret")
public void shouldNotThrowConflictExceptionIfNoExpectationsInUrl() throws URISyntaxException, UnsupportedEncodingException {
when(pullRequestService.get(any(), any(), any())).thenReturn(PULL_REQUEST);
when(branchRevisionResolver.getRevisions(any(), eq(PULL_REQUEST))).thenReturn(new BranchRevisionResolver.RevisionResult("source", "target"));
byte[] commentJson = "{\"comment\" : \"this is my comment\"}".getBytes();
MockHttpRequest request = MockHttpRequest.post("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/space/name/1/comments").content(commentJson).contentType(MediaType.APPLICATION_JSON);
dispatcher.invoke(request, response);
assertEquals(HttpServletResponse.SC_CREATED, response.getStatus());
}
Aggregations