Search in sources :

Example 6 with KillBillClientException

use of org.killbill.billing.client.KillBillClientException in project killbill by killbill.

the class TestSecurity method testUserWithUpdates.

@Test(groups = "slow")
public void testUserWithUpdates() throws KillBillClientException {
    final String roleDefinition = "somethingNice";
    final String allPermissions = "*";
    final String username = "GuanYu";
    final String password = "IamAGreatWarrior";
    Response response = killBillClient.addRoleDefinition(new RoleDefinition(roleDefinition, ImmutableList.of(allPermissions)), createdBy, reason, comment);
    Assert.assertEquals(response.getStatusCode(), 201);
    response = killBillClient.addUserRoles(new UserRoles(username, password, ImmutableList.of(roleDefinition)), createdBy, reason, comment);
    Assert.assertEquals(response.getStatusCode(), 201);
    logout();
    login(username, password);
    Permissions permissions = killBillClient.getPermissions();
    Assert.assertEquals(permissions.size(), Permission.values().length);
    String newPassword = "IamTheBestWarrior";
    killBillClient.updateUserPassword(username, newPassword, createdBy, reason, comment);
    logout();
    login(username, newPassword);
    permissions = killBillClient.getPermissions();
    Assert.assertEquals(permissions.size(), Permission.values().length);
    final String newRoleDefinition = "somethingLessNice";
    // Only enough permissions to invalidate itself in the last step...
    final String littlePermissions = "user";
    response = killBillClient.addRoleDefinition(new RoleDefinition(newRoleDefinition, ImmutableList.of(littlePermissions)), createdBy, reason, comment);
    Assert.assertEquals(response.getStatusCode(), 201);
    killBillClient.updateUserRoles(username, ImmutableList.of(newRoleDefinition), createdBy, reason, comment);
    permissions = killBillClient.getPermissions();
    // This will only work if correct shiro cache invalidation was performed... requires lots of sweat to get it to work ;-)
    Assert.assertEquals(permissions.size(), 2);
    killBillClient.invalidateUser(username, createdBy, reason, comment);
    try {
        killBillClient.getPermissions();
        Assert.fail();
    } catch (final KillBillClientException e) {
        Assert.assertEquals(e.getResponse().getStatusCode(), Status.UNAUTHORIZED.getStatusCode());
    }
}
Also used : Response(com.ning.http.client.Response) UserRoles(org.killbill.billing.client.model.UserRoles) RoleDefinition(org.killbill.billing.client.model.RoleDefinition) Permissions(org.killbill.billing.client.model.Permissions) KillBillClientException(org.killbill.billing.client.KillBillClientException) Test(org.testng.annotations.Test)

Example 7 with KillBillClientException

use of org.killbill.billing.client.KillBillClientException in project killbill by killbill.

the class TestSecurity method testUserPermission.

@Test(groups = "slow")
public void testUserPermission() throws KillBillClientException {
    final String roleDefinition = "notEnoughToAddUserAndRoles";
    final List<String> permissions = new ArrayList<String>();
    for (Permission cur : Permission.values()) {
        if (!cur.getGroup().equals("user")) {
            permissions.add(cur.toString());
        }
    }
    Response response = killBillClient.addRoleDefinition(new RoleDefinition(roleDefinition, permissions), createdBy, reason, comment);
    Assert.assertEquals(response.getStatusCode(), 201);
    final String username = "candy";
    final String password = "lolipop";
    response = killBillClient.addUserRoles(new UserRoles(username, password, ImmutableList.of(roleDefinition)), createdBy, reason, comment);
    Assert.assertEquals(response.getStatusCode(), 201);
    // Now 'login' as new user (along with roles to make an API call requiring permissions), and check behavior
    logout();
    login(username, password);
    boolean success = false;
    try {
        killBillClient.addRoleDefinition(new RoleDefinition("dsfdsfds", ImmutableList.of("*")), createdBy, reason, comment);
        success = true;
    } catch (final Exception e) {
    } finally {
        Assert.assertFalse(success);
    }
    success = false;
    try {
        killBillClient.addUserRoles(new UserRoles("sdsd", "sdsdsd", ImmutableList.of(roleDefinition)), createdBy, reason, comment);
        success = true;
    } catch (final Exception e) {
    } finally {
        Assert.assertFalse(success);
    }
}
Also used : Response(com.ning.http.client.Response) UserRoles(org.killbill.billing.client.model.UserRoles) ArrayList(java.util.ArrayList) Permission(org.killbill.billing.security.Permission) RoleDefinition(org.killbill.billing.client.model.RoleDefinition) KillBillClientException(org.killbill.billing.client.KillBillClientException) Test(org.testng.annotations.Test)

Example 8 with KillBillClientException

use of org.killbill.billing.client.KillBillClientException in project killbill by killbill.

the class TestTag method testTagErrorHandling.

@Test(groups = "slow", description = "Cannot add badly formatted TagDefinition")
public void testTagErrorHandling() throws Exception {
    final TagDefinition[] tagDefinitions = { new TagDefinition(null, false, null, null, null), new TagDefinition(null, false, "something", null, null), new TagDefinition(null, false, null, "something", null) };
    for (final TagDefinition tagDefinition : tagDefinitions) {
        try {
            killBillClient.createTagDefinition(tagDefinition, requestOptions);
            fail();
        } catch (final KillBillClientException e) {
        }
    }
}
Also used : TagDefinition(org.killbill.billing.client.model.TagDefinition) KillBillClientException(org.killbill.billing.client.KillBillClientException) Test(org.testng.annotations.Test)

Example 9 with KillBillClientException

use of org.killbill.billing.client.KillBillClientException in project killbill by killbill.

the class TestPayment method testAuthorizeCompletionUsingPaymentIdAndTransactionId.

@Test(groups = "slow")
public void testAuthorizeCompletionUsingPaymentIdAndTransactionId() throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod();
    final UUID paymentMethodId = account.getPaymentMethodId();
    final BigDecimal amount = BigDecimal.TEN;
    final String pending = PaymentPluginStatus.PENDING.toString();
    final ImmutableMap<String, String> pendingPluginProperties = ImmutableMap.<String, String>of(MockPaymentProviderPlugin.PLUGIN_PROPERTY_PAYMENT_PLUGIN_STATUS_OVERRIDE, pending);
    final ImmutableMap<String, String> pluginProperties = ImmutableMap.of();
    TransactionType transactionType = TransactionType.AUTHORIZE;
    final String paymentExternalKey = UUID.randomUUID().toString();
    final String authTransactionExternalKey = UUID.randomUUID().toString();
    final Payment initialPayment = createVerifyTransaction(account, paymentMethodId, paymentExternalKey, authTransactionExternalKey, transactionType, pending, amount, BigDecimal.ZERO, pendingPluginProperties, 1);
    final PaymentTransaction completeTransactionByPaymentIdAndInvalidTransactionId = new PaymentTransaction();
    completeTransactionByPaymentIdAndInvalidTransactionId.setPaymentId(initialPayment.getPaymentId());
    completeTransactionByPaymentIdAndInvalidTransactionId.setTransactionId(UUID.randomUUID());
    try {
        killBillClient.completePayment(completeTransactionByPaymentIdAndInvalidTransactionId, pluginProperties, requestOptions);
        fail("Payment completion should fail when invalid transaction id has been provided");
    } catch (final KillBillClientException expected) {
    }
    final PaymentTransaction completeTransactionByPaymentIdAndTransactionId = new PaymentTransaction();
    completeTransactionByPaymentIdAndTransactionId.setPaymentId(initialPayment.getPaymentId());
    completeTransactionByPaymentIdAndTransactionId.setTransactionId(initialPayment.getTransactions().get(0).getTransactionId());
    final Payment completedPaymentByPaymentId = killBillClient.completePayment(completeTransactionByPaymentIdAndTransactionId, pluginProperties, requestOptions);
    verifyPayment(account, paymentMethodId, completedPaymentByPaymentId, paymentExternalKey, authTransactionExternalKey, transactionType.toString(), TransactionStatus.SUCCESS.name(), amount, amount, BigDecimal.ZERO, BigDecimal.ZERO, 1, 1);
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.ComboPaymentTransaction) Account(org.killbill.billing.client.model.Account) TransactionType(org.killbill.billing.payment.api.TransactionType) Payment(org.killbill.billing.client.model.Payment) KillBillClientException(org.killbill.billing.client.KillBillClientException) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 10 with KillBillClientException

use of org.killbill.billing.client.KillBillClientException in project killbill by killbill.

the class TestChargeback method testInvoicePaymentDoesNotExist.

@Test(groups = "slow", description = "Cannot add a chargeback for non existent payment")
public void testInvoicePaymentDoesNotExist() {
    final InvoicePaymentTransaction input = new InvoicePaymentTransaction();
    input.setPaymentId(input.getPaymentId());
    input.setAmount(BigDecimal.TEN);
    try {
        killBillClient.createInvoicePaymentChargeback(input, createdBy, reason, comment);
        fail();
    } catch (NullPointerException e) {
    } catch (KillBillClientException e) {
        fail();
    }
}
Also used : InvoicePaymentTransaction(org.killbill.billing.client.model.InvoicePaymentTransaction) KillBillClientException(org.killbill.billing.client.KillBillClientException) Test(org.testng.annotations.Test)

Aggregations

KillBillClientException (org.killbill.billing.client.KillBillClientException)21 Test (org.testng.annotations.Test)20 Account (org.killbill.billing.client.model.Account)13 ComboPaymentTransaction (org.killbill.billing.client.model.ComboPaymentTransaction)7 PaymentTransaction (org.killbill.billing.client.model.PaymentTransaction)6 UUID (java.util.UUID)5 Payment (org.killbill.billing.client.model.Payment)5 BigDecimal (java.math.BigDecimal)3 InvoicePaymentTransaction (org.killbill.billing.client.model.InvoicePaymentTransaction)3 TransactionType (org.killbill.billing.payment.api.TransactionType)3 Response (com.ning.http.client.Response)2 RequestOptions (org.killbill.billing.client.RequestOptions)2 InvoicePayment (org.killbill.billing.client.model.InvoicePayment)2 RoleDefinition (org.killbill.billing.client.model.RoleDefinition)2 Tenant (org.killbill.billing.client.model.Tenant)2 UserRoles (org.killbill.billing.client.model.UserRoles)2 Predicate (com.google.common.base.Predicate)1 ArrayList (java.util.ArrayList)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Bundle (org.killbill.billing.client.model.Bundle)1