use of uk.gov.pay.api.auth.Account in project pay-publicapi by alphagov.
the class RateLimiterFilterTest method shouldSendErrorResponse_whenRateLimitExceeded.
@Test
public void shouldSendErrorResponse_whenRateLimitExceeded() throws Exception {
Account account = new Account(ACCOUNT_ID, TokenPaymentType.CARD, "some-token-link");
SecurityContext mockSecurityContext = mock(SecurityContext.class);
when(mockSecurityContext.getUserPrincipal()).thenReturn(account);
when(mockContainerRequestContext.getSecurityContext()).thenReturn(mockSecurityContext);
when(mockContainerRequestContext.getMethod()).thenReturn("GET");
doThrow(RateLimitException.class).when(rateLimiter).checkRateOf(eq("account-id"), any());
WebApplicationException webApplicationException = assertThrows(WebApplicationException.class, () -> rateLimiterFilter.filter(mockContainerRequestContext));
Response response = webApplicationException.getResponse();
assertEquals(429, response.getStatus());
assertEquals("application/json", response.getHeaderString("Content-Type"));
assertEquals("utf-8", response.getHeaderString("Content-Encoding"));
assertEquals("{\"code\":\"P0900\",\"description\":\"Too many requests\"}", response.getEntity());
}
use of uk.gov.pay.api.auth.Account in project pay-publicapi by alphagov.
the class RateLimiterFilterTest method shouldCheckRateLimitsWhenFilterIsInvoked.
@Test
public void shouldCheckRateLimitsWhenFilterIsInvoked() throws Exception {
Account account = new Account(ACCOUNT_ID, TokenPaymentType.CARD, "some-token-link");
SecurityContext mockSecurityContext = mock(SecurityContext.class);
when(mockSecurityContext.getUserPrincipal()).thenReturn(account);
when(mockContainerRequestContext.getSecurityContext()).thenReturn(mockSecurityContext);
when(mockContainerRequestContext.getMethod()).thenReturn("GET");
when(mockContainerRequestContext.getMethod()).thenReturn("POST");
rateLimiterFilter.filter(mockContainerRequestContext);
verify(rateLimiter).checkRateOf(eq(ACCOUNT_ID), any());
}
use of uk.gov.pay.api.auth.Account in project pay-publicapi by alphagov.
the class CachingAuthenticatorIT method setup.
@Before
public void setup() throws Exception {
String tokenLink = "some-token-link";
stubPublicAuthV1ApiAuth(publicAuthRule, new Account(accountId, CARD, tokenLink), bearerToken);
setUpMockForConnector();
}
use of uk.gov.pay.api.auth.Account in project pay-publicapi by alphagov.
the class CreatePaymentServiceTest method shouldThrowExceptionWithIdentifierMissingMandatoryAttribute_whenReturnUrlMissing.
@Test
@PactVerification({ "connector" })
@Pacts(pacts = { "publicapi-connector-create-payment-with-missing-return-url" })
public void shouldThrowExceptionWithIdentifierMissingMandatoryAttribute_whenReturnUrlMissing() {
Account account = new Account("444", TokenPaymentType.CARD, "a-token-link");
var requestPayload = CreateCardPaymentRequestBuilder.builder().amount(100).reference("a reference").description("a description").build();
try {
createPaymentService.create(account, requestPayload);
fail("Expected CreateChargeException to be thrown");
} catch (CreateChargeException e) {
assertThat(e.getErrorIdentifier(), is(ErrorIdentifier.MISSING_MANDATORY_ATTRIBUTE));
assertThat(e.getConnectorErrorMessage(), is("Missing mandatory attribute: return_url"));
}
}
use of uk.gov.pay.api.auth.Account in project pay-publicapi by alphagov.
the class CreatePaymentServiceTest method setup.
@Before
public void setup() {
// We will actually send real requests here, which will be intercepted by pact
when(configuration.getConnectorUrl()).thenReturn(connectorRule.getUrl());
when(configuration.getBaseUrl()).thenReturn("http://publicapi.test.localhost/");
PublicApiUriGenerator publicApiUriGenerator = new PublicApiUriGenerator(configuration);
ConnectorUriGenerator connectorUriGenerator = new ConnectorUriGenerator(configuration);
Client client = RestClientFactory.buildClient(new RestClientConfig(false));
createPaymentService = new CreatePaymentService(client, publicApiUriGenerator, connectorUriGenerator);
account = new Account("123456", TokenPaymentType.CARD, "a-token-link");
}
Aggregations