Skip to content

Commit bbbf783

Browse files
authored
fix potential NPE and fix failing tests (#61)
* fix potential NPE and fix failing tests * updated CHANGELOG.md * Make tests use a different test account Co-authored-by: Juhan Aasaru <Juhan.Aasaru@nortal.com>
1 parent 08f3bc9 commit bbbf783

7 files changed

Lines changed: 66 additions & 32 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
All notable changes to this project will be documented in this file.
33
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
44

5+
## [2.1.3] - UPCOMING
6+
7+
### Fixed
8+
- Possible NPE fix (in rare cases under load testing the SessionStatus is null)
9+
10+
### Changes in tests
11+
- Changed document number in tests
12+
- Added a flag (SmartIdIntegrationTest.TEST_AGAINST_SMART_ID_DEMO) to switch off tests that make requests to Smart-ID demo env.
13+
514
## [2.1.2] - 2021-11-03
615

716
### Changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ String verificationCode = authenticationHash.calculateVerificationCode();
200200
201201
SmartIdAuthenticationResponse authenticationResponse = client
202202
.createAuthentication()
203-
.withDocumentNumber("PNOEE-30303039914-5QSV-Q")
203+
.withDocumentNumber("PNOLT-30303039914-PBZK-Q")
204204
.withAuthenticationHash(authenticationHash)
205205
.withCertificateLevel("QUALIFIED")
206206
.withAllowedInteractionsOrder(Collections.singletonList(
@@ -254,7 +254,7 @@ To fetch the certificate you can use documentNumber.
254254
```
255255
SmartIdCertificate responseWithSigningCertificate = client
256256
.getCertificate()
257-
.withDocumentNumber("PNOEE-30303039914-5QSV-Q") // returned as authentication result
257+
.withDocumentNumber("PNOLT-30303039914-PBZK-Q") // returned as authentication result
258258
.withCertificateLevel("QUALIFIED")
259259
.fetch();
260260
@@ -291,7 +291,7 @@ String verificationCode = hashToSign.calculateVerificationCode();
291291
292292
SmartIdSignature smartIdSignature = client
293293
.createSignature()
294-
.withDocumentNumber("PNOEE-30303039914-5QSV-Q") // returned as authentication result
294+
.withDocumentNumber("PNOLT-30303039914-PBZK-Q") // returned as authentication result
295295
.withSignableHash(hashToSign)
296296
.withCertificateLevel("QUALIFIED")
297297
.withAllowedInteractionsOrder(asList(
@@ -335,7 +335,7 @@ Every Smart-ID app supports this interaction flow and there is no need to provid
335335
```
336336
SmartIdSignature smartIdSignature = client
337337
.createSignature()
338-
.withDocumentNumber("PNOEE-30303039914-5QSV-Q")
338+
.withDocumentNumber("PNOLT-30303039914-PBZK-Q")
339339
.withSignableHash(hashToSign)
340340
.withCertificateLevel("QUALIFIED")
341341
.withAllowedInteractionsOrder(Collections.singletonList(
@@ -357,7 +357,7 @@ If user's app doesn't support displaying verification code choice then system fa
357357
try {
358358
SmartIdSignature smartIdSignature = client
359359
.createSignature()
360-
.withDocumentNumber("PNOEE-30303039914-5QSV-Q")
360+
.withDocumentNumber("PNOLT-30303039914-PBZK-Q")
361361
.withSignableHash(hashToSign)
362362
.withCertificateLevel("QUALIFIED")
363363
.withAllowedInteractionsOrder(Arrays.asList(
@@ -380,7 +380,7 @@ If the Smart-ID app in user's smart device doesn't support this feature then the
380380
```
381381
SmartIdSignature smartIdSignature = client
382382
.createSignature()
383-
.withDocumentNumber("PNOEE-30303039914-5QSV-Q")
383+
.withDocumentNumber("PNOLT-30303039914-PBZK-Q")
384384
.withSignableHash(hashToSign)
385385
.withCertificateLevel("QUALIFIED")
386386
.withAllowedInteractionsOrder(asList(
@@ -408,7 +408,7 @@ If user picks wrong verification code then the session is cancelled and library
408408
```
409409
SmartIdSignature smartIdSignature = client
410410
.createSignature()
411-
.withDocumentNumber("PNOEE-30303039914-5QSV-Q")
411+
.withDocumentNumber("PNOLT-30303039914-PBZK-Q")
412412
.withSignableHash(hashToSign)
413413
.withCertificateLevel("QUALIFIED")
414414
.withAllowedInteractionsOrder(asList(
@@ -439,7 +439,7 @@ If End User's phone doesn't support required flow the library throws `RequiredIn
439439
try {
440440
client
441441
.createSignature()
442-
.withDocumentNumber("PNOEE-30303039914-5QSV-Q")
442+
.withDocumentNumber("PNOLT-30303039914-PBZK-Q")
443443
.withSignableHash(hashToSign)
444444
.withCertificateLevel("QUALIFIED")
445445
.withAllowedInteractionsOrder(Collections.singletonList(

src/main/java/ee/sk/smartid/rest/SessionStatusPoller.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private SessionStatus pollForFinalSessionStatus(String sessionId) throws Interru
6464
SessionStatus sessionStatus = null;
6565
while (sessionStatus == null || equalsIgnoreCase("RUNNING", sessionStatus.getState())) {
6666
sessionStatus = pollSessionStatus(sessionId);
67-
if (equalsIgnoreCase("COMPLETE", sessionStatus.getState())) {
67+
if (sessionStatus != null && equalsIgnoreCase("COMPLETE", sessionStatus.getState())) {
6868
break;
6969
}
7070
logger.debug("Sleeping for " + pollingSleepTimeout + " " + pollingSleepTimeUnit);

src/test/java/ee/sk/smartid/EndpointSslVerificationIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class EndpointSslVerificationIntegrationTest {
2929
private static final String LIVE_HOST_URL = "https://rp-api.smart-id.com/v1";
3030
private static final String DEMO_RELYING_PARTY_UUID = "00000000-0000-0000-0000-000000000000";
3131
private static final String DEMO_RELYING_PARTY_NAME = "DEMO";
32-
private static final String DEMO_DOCUMENT_NUMBER = "PNOEE-30303039914-5QSV-Q";
32+
private static final String DEMO_DOCUMENT_NUMBER = "PNOLT-30303039914-PBZK-Q";
3333

3434
public static final String LIVE_HOST_SSL_CERTIFICATE = "-----BEGIN CERTIFICATE-----\nMIIGjjCCBXagAwIBAgIQA6feGFsbcuz3yYop3036xzANBgkqhkiG9w0BAQsFADBN\nMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMScwJQYDVQQDEx5E\naWdpQ2VydCBTSEEyIFNlY3VyZSBTZXJ2ZXIgQ0EwHhcNMTkxMTAxMDAwMDAwWhc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test/java/ee/sk/smartid/rest/SmartIdRestIntegrationTest.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,19 @@
3737
import java.util.Collections;
3838
import java.util.concurrent.TimeUnit;
3939

40+
import static ee.sk.test.smartid.integration.SmartIdIntegrationTest.TEST_AGAINST_SMART_ID_DEMO;
4041
import static java.util.Arrays.asList;
42+
import static junit.framework.TestCase.assertEquals;
43+
import static junit.framework.TestCase.assertNotNull;
44+
import static org.hamcrest.MatcherAssert.assertThat;
4145
import static org.hamcrest.Matchers.*;
42-
import static org.junit.Assert.*;
46+
import static org.junit.Assume.assumeTrue;
4347

4448
public class SmartIdRestIntegrationTest {
4549

4650
private static final String RELYING_PARTY_UUID = "00000000-0000-0000-0000-000000000000";
4751
private static final String RELYING_PARTY_NAME = "DEMO";
48-
private static final String DOCUMENT_NUMBER = "PNOEE-30303039914-5QSV-Q";
52+
private static final String DOCUMENT_NUMBER = "PNOLT-30303039903-FMB7-Q";
4953
private static final String DOCUMENT_NUMBER_LT = "PNOLT-30303039914-PBZK-Q";
5054
private static final String DATA_TO_SIGN = "Hello World!";
5155
private static final String CERTIFICATE_LEVEL_QUALIFIED = "QUALIFIED";
@@ -54,6 +58,9 @@ public class SmartIdRestIntegrationTest {
5458
@Before
5559
public void setUp() {
5660
connector = new SmartIdRestConnector("https://sid.demo.sk.ee/smart-id-rp/v2/");
61+
62+
// this allows to switch off tests going against smart-id demo env
63+
assumeTrue(TEST_AGAINST_SMART_ID_DEMO);
5764
}
5865

5966
@Test
@@ -93,12 +100,13 @@ public void authenticate_withDocumentNumber() throws Exception {
93100

94101
SessionStatus sessionStatus = pollSessionStatus(authenticationSessionResponse.getSessionID());
95102

103+
assertNotNull(sessionStatus.getResult());
104+
assertThat(sessionStatus.getResult().getEndResult(), is("OK"));
96105
assertThat(sessionStatus.getInteractionFlowUsed(), is("displayTextAndPIN"));
97106

98107
assertAuthenticationResponseCreated(sessionStatus);
99108
}
100109

101-
102110
@Test
103111
public void authenticate_withDocumentNumber_advancedInteraction() throws Exception {
104112
AuthenticationSessionRequest authenticationSessionRequest = new AuthenticationSessionRequest();
@@ -119,6 +127,8 @@ public void authenticate_withDocumentNumber_advancedInteraction() throws Excepti
119127

120128
SessionStatus sessionStatus = pollSessionStatus(authenticationSessionResponse.getSessionID());
121129

130+
assertNotNull(sessionStatus.getResult());
131+
assertThat(sessionStatus.getResult().getEndResult(), is("OK"));
122132
org.hamcrest.MatcherAssert.assertThat(sessionStatus.getInteractionFlowUsed(), is("confirmationMessage"));
123133

124134
assertAuthenticationResponseCreated(sessionStatus);
@@ -138,6 +148,8 @@ public void getIgnoredProperties_withSign_getIgnoredProperties_withAuthenticate_
138148
SignatureSessionResponse signatureSessionResponse = fetchSignatureSession(documentNumber, signatureSessionRequest);
139149
sessionStatus = pollSessionStatus(signatureSessionResponse.getSessionID());
140150

151+
assertNotNull(sessionStatus.getResult());
152+
assertThat(sessionStatus.getResult().getEndResult(), is("OK"));
141153
assertThat(sessionStatus.getInteractionFlowUsed(), is("displayTextAndPIN"));
142154

143155

src/test/java/ee/sk/test/smartid/integration/ReadmeTest.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
import java.util.Optional;
2828
import java.util.concurrent.TimeUnit;
2929

30+
import static ee.sk.test.smartid.integration.SmartIdIntegrationTest.TEST_AGAINST_SMART_ID_DEMO;
3031
import static java.util.Arrays.asList;
32+
import static org.junit.Assume.assumeTrue;
3133

3234
/**
3335
* These tests contain snippets used in Readme.md
@@ -99,6 +101,8 @@ public void setUp() {
99101
// this class also has a method to set hash as bite array
100102
hashToSign.setHashInBase64("0nbgC2fVdLVQFZJdBbmG7oPoElpCYsQMtrY0c0wKYRg=");
101103

104+
// this allows to switch off tests going against smart-id demo env
105+
assumeTrue(TEST_AGAINST_SMART_ID_DEMO);
102106
}
103107

104108
/*
@@ -176,11 +180,10 @@ public void documentConfigureTheClient_feedSeparately() {
176180

177181
@Test
178182
public void documentAuthenticatingWithSemanticsIdentifier() {
179-
180183
SemanticsIdentifier semanticsIdentifier = new SemanticsIdentifier(
181184
SemanticsIdentifier.IdentityType.PNO, // 3 character identity type (PAS-passport, IDC-national identity card or PNO - (national) personal number)
182-
SemanticsIdentifier.CountryCode.EE, // 2 character ISO 3166-1 alpha-2 country code
183-
"30303039914"); // identifier (according to country and identity type reference)
185+
SemanticsIdentifier.CountryCode.LT, // 2 character ISO 3166-1 alpha-2 country code
186+
"30303039903"); // identifier (according to country and identity type reference)
184187

185188
// For security reasons a new hash value must be created for each new authentication request
186189
AuthenticationHash authenticationHash = AuthenticationHash.generateRandomHash();
@@ -231,7 +234,7 @@ public void documentAuthenticatingWithDocumentNumber() {
231234

232235
SmartIdAuthenticationResponse authenticationResponse = client
233236
.createAuthentication()
234-
.withDocumentNumber("PNOEE-30303039914-5QSV-Q")
237+
.withDocumentNumber("PNOEE-30303039903-1DNH-Q")
235238
.withAuthenticationHash(authenticationHash)
236239
.withCertificateLevel("QUALIFIED")
237240
.withAllowedInteractionsOrder(Collections.singletonList(
@@ -294,7 +297,7 @@ public void documentObtainingUsersCertificate() {
294297

295298
SmartIdCertificate responseWithSigningCertificate = client
296299
.getCertificate()
297-
.withDocumentNumber("PNOEE-30303039914-5QSV-Q") // returned as authentication result
300+
.withDocumentNumber("PNOEE-30303039903-1DNH-Q") // returned as authentication result
298301
.withCertificateLevel("QUALIFIED")
299302
.fetch();
300303

@@ -340,7 +343,7 @@ public void documentCreatingSignature() {
340343

341344
SmartIdSignature smartIdSignature = client
342345
.createSignature()
343-
.withDocumentNumber("PNOEE-30303039914-5QSV-Q") // returned as authentication result
346+
.withDocumentNumber("PNOLT-30303039914-PBZK-Q") // returned as authentication result
344347
.withSignableHash(hashToSign)
345348
.withCertificateLevel("QUALIFIED")
346349
.withAllowedInteractionsOrder(asList(
@@ -389,7 +392,7 @@ public void documentCreatingSignature() {
389392
public void documentInteractionOrderMostCommon() {
390393
SmartIdSignature smartIdSignature = client
391394
.createSignature()
392-
.withDocumentNumber("PNOEE-30303039914-5QSV-Q")
395+
.withDocumentNumber("PNOLT-30303039914-PBZK-Q")
393396
.withSignableHash(hashToSign)
394397
.withCertificateLevel("QUALIFIED")
395398
.withAllowedInteractionsOrder(Collections.singletonList(
@@ -416,7 +419,7 @@ public void documentInteractionOrderVerificationChoice() {
416419
try {
417420
SmartIdSignature smartIdSignature = client
418421
.createSignature()
419-
.withDocumentNumber("PNOEE-30303039914-5QSV-Q")
422+
.withDocumentNumber("PNOLT-30303039914-PBZK-Q")
420423
.withSignableHash(hashToSign)
421424
.withCertificateLevel("QUALIFIED")
422425
.withAllowedInteractionsOrder(Arrays.asList(
@@ -444,7 +447,7 @@ public void documentInteractionOrderVerificationChoice() {
444447
public void documentInteractionOrderConfirmationWithFallbackToPin() {
445448
SmartIdSignature smartIdSignature = client
446449
.createSignature()
447-
.withDocumentNumber("PNOEE-30303039914-5QSV-Q")
450+
.withDocumentNumber("PNOLT-30303039914-PBZK-Q") //
448451
.withSignableHash(hashToSign)
449452
.withCertificateLevel("QUALIFIED")
450453
.withAllowedInteractionsOrder(asList(
@@ -476,7 +479,7 @@ else if (InteractionFlow.DISPLAY_TEXT_AND_PIN.is(smartIdSignature.getInteraction
476479
public void documentInteractionOrder2() {
477480
SmartIdSignature smartIdSignature = client
478481
.createSignature()
479-
.withDocumentNumber("PNOEE-30303039914-5QSV-Q")
482+
.withDocumentNumber("PNOEE-30303039903-1DNH-Q")
480483
.withSignableHash(hashToSign)
481484
.withCertificateLevel("QUALIFIED")
482485
.withAllowedInteractionsOrder(asList(
@@ -512,7 +515,7 @@ public void documentInteractionOrderWithoutFallback() {
512515
try {
513516
client
514517
.createSignature()
515-
.withDocumentNumber("PNOEE-30303039914-5QSV-Q")
518+
.withDocumentNumber("PNOLT-30303039914-PBZK-Q")
516519
.withSignableHash(hashToSign)
517520
.withCertificateLevel("QUALIFIED")
518521
.withAllowedInteractionsOrder(Collections.singletonList(

0 commit comments

Comments
 (0)