forked from Mastercard/open-banking-us-openapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuthenticationApiTest.java
64 lines (56 loc) · 2.11 KB
/
AuthenticationApiTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package com.mastercard.finicity.client.api;
import com.mastercard.finicity.client.ApiException;
import com.mastercard.finicity.client.model.PartnerCredentials;
import com.mastercard.finicity.client.model.PartnerCredentialsWithNewSecret;
import com.mastercard.finicity.client.test.BaseTest;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
class AuthenticationApiTest extends BaseTest {
private final AuthenticationApi api = new AuthenticationApi(apiClient);
@Test
void createTokenTest() {
try {
var response = api.createToken(new PartnerCredentials()
.partnerId(PARTNER_ID)
.partnerSecret(PARTNER_SECRET));
assertNotNull(response);
assertNotNull(response.getToken());
} catch (ApiException e) {
fail(e);
}
}
@Test
void modifyPartnerSecretTest() {
PartnerCredentialsWithNewSecret credentials;
try {
// 1. Update Partner Secret
credentials = new PartnerCredentialsWithNewSecret()
.partnerId(PARTNER_ID)
.partnerSecret(PARTNER_SECRET)
.newPartnerSecret(PARTNER_SECRET + "_updated");
api.modifyPartnerSecret(credentials);
} catch (ApiException e) {
fail(e);
}
try {
// 2. Try to get a token using the old secret
api.createToken(new PartnerCredentials()
.partnerId(PARTNER_ID)
.partnerSecret(PARTNER_SECRET));
fail();
} catch (ApiException e) {
// {"code":10001,"message":"Invalid credentials"}
logApiException(e);
}
try {
// 3. Rollback
credentials = new PartnerCredentialsWithNewSecret()
.partnerId(PARTNER_ID)
.partnerSecret(PARTNER_SECRET + "_updated")
.newPartnerSecret(PARTNER_SECRET);
api.modifyPartnerSecret(credentials);
} catch (ApiException e) {
fail(e);
}
}
}