Skip to content

Commit

Permalink
fix potential NPE and fix failing tests (#61)
Browse files Browse the repository at this point in the history
* fix potential NPE and fix failing tests
* updated CHANGELOG.md
* Make tests use a different test account

Co-authored-by: Juhan Aasaru <[email protected]>
  • Loading branch information
aasaru and aasaru authored Dec 22, 2021
1 parent 08f3bc9 commit bbbf783
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 32 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [2.1.3] - UPCOMING

### Fixed
- Possible NPE fix (in rare cases under load testing the SessionStatus is null)

### Changes in tests
- Changed document number in tests
- Added a flag (SmartIdIntegrationTest.TEST_AGAINST_SMART_ID_DEMO) to switch off tests that make requests to Smart-ID demo env.

## [2.1.2] - 2021-11-03

### Changed
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ String verificationCode = authenticationHash.calculateVerificationCode();
SmartIdAuthenticationResponse authenticationResponse = client
.createAuthentication()
.withDocumentNumber("PNOEE-30303039914-5QSV-Q")
.withDocumentNumber("PNOLT-30303039914-PBZK-Q")
.withAuthenticationHash(authenticationHash)
.withCertificateLevel("QUALIFIED")
.withAllowedInteractionsOrder(Collections.singletonList(
Expand Down Expand Up @@ -254,7 +254,7 @@ To fetch the certificate you can use documentNumber.
```
SmartIdCertificate responseWithSigningCertificate = client
.getCertificate()
.withDocumentNumber("PNOEE-30303039914-5QSV-Q") // returned as authentication result
.withDocumentNumber("PNOLT-30303039914-PBZK-Q") // returned as authentication result
.withCertificateLevel("QUALIFIED")
.fetch();
Expand Down Expand Up @@ -291,7 +291,7 @@ String verificationCode = hashToSign.calculateVerificationCode();
SmartIdSignature smartIdSignature = client
.createSignature()
.withDocumentNumber("PNOEE-30303039914-5QSV-Q") // returned as authentication result
.withDocumentNumber("PNOLT-30303039914-PBZK-Q") // returned as authentication result
.withSignableHash(hashToSign)
.withCertificateLevel("QUALIFIED")
.withAllowedInteractionsOrder(asList(
Expand Down Expand Up @@ -335,7 +335,7 @@ Every Smart-ID app supports this interaction flow and there is no need to provid
```
SmartIdSignature smartIdSignature = client
.createSignature()
.withDocumentNumber("PNOEE-30303039914-5QSV-Q")
.withDocumentNumber("PNOLT-30303039914-PBZK-Q")
.withSignableHash(hashToSign)
.withCertificateLevel("QUALIFIED")
.withAllowedInteractionsOrder(Collections.singletonList(
Expand All @@ -357,7 +357,7 @@ If user's app doesn't support displaying verification code choice then system fa
try {
SmartIdSignature smartIdSignature = client
.createSignature()
.withDocumentNumber("PNOEE-30303039914-5QSV-Q")
.withDocumentNumber("PNOLT-30303039914-PBZK-Q")
.withSignableHash(hashToSign)
.withCertificateLevel("QUALIFIED")
.withAllowedInteractionsOrder(Arrays.asList(
Expand All @@ -380,7 +380,7 @@ If the Smart-ID app in user's smart device doesn't support this feature then the
```
SmartIdSignature smartIdSignature = client
.createSignature()
.withDocumentNumber("PNOEE-30303039914-5QSV-Q")
.withDocumentNumber("PNOLT-30303039914-PBZK-Q")
.withSignableHash(hashToSign)
.withCertificateLevel("QUALIFIED")
.withAllowedInteractionsOrder(asList(
Expand Down Expand Up @@ -408,7 +408,7 @@ If user picks wrong verification code then the session is cancelled and library
```
SmartIdSignature smartIdSignature = client
.createSignature()
.withDocumentNumber("PNOEE-30303039914-5QSV-Q")
.withDocumentNumber("PNOLT-30303039914-PBZK-Q")
.withSignableHash(hashToSign)
.withCertificateLevel("QUALIFIED")
.withAllowedInteractionsOrder(asList(
Expand Down Expand Up @@ -439,7 +439,7 @@ If End User's phone doesn't support required flow the library throws `RequiredIn
try {
client
.createSignature()
.withDocumentNumber("PNOEE-30303039914-5QSV-Q")
.withDocumentNumber("PNOLT-30303039914-PBZK-Q")
.withSignableHash(hashToSign)
.withCertificateLevel("QUALIFIED")
.withAllowedInteractionsOrder(Collections.singletonList(
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ee/sk/smartid/rest/SessionStatusPoller.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private SessionStatus pollForFinalSessionStatus(String sessionId) throws Interru
SessionStatus sessionStatus = null;
while (sessionStatus == null || equalsIgnoreCase("RUNNING", sessionStatus.getState())) {
sessionStatus = pollSessionStatus(sessionId);
if (equalsIgnoreCase("COMPLETE", sessionStatus.getState())) {
if (sessionStatus != null && equalsIgnoreCase("COMPLETE", sessionStatus.getState())) {
break;
}
logger.debug("Sleeping for " + pollingSleepTimeout + " " + pollingSleepTimeUnit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class EndpointSslVerificationIntegrationTest {
private static final String LIVE_HOST_URL = "https://rp-api.smart-id.com/v1";
private static final String DEMO_RELYING_PARTY_UUID = "00000000-0000-0000-0000-000000000000";
private static final String DEMO_RELYING_PARTY_NAME = "DEMO";
private static final String DEMO_DOCUMENT_NUMBER = "PNOEE-30303039914-5QSV-Q";
private static final String DEMO_DOCUMENT_NUMBER = "PNOLT-30303039914-PBZK-Q";

public static final String LIVE_HOST_SSL_CERTIFICATE = "-----BEGIN CERTIFICATE-----\nMIIGjjCCBXagAwIBAgIQA6feGFsbcuz3yYop3036xzANBgkqhkiG9w0BAQsFADBN\nMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMScwJQYDVQQDEx5E\naWdpQ2VydCBTSEEyIFNlY3VyZSBTZXJ2ZXIgQ0EwHhcNMTkxMTAxMDAwMDAwWhcN\nMjExMTA1MTIwMDAwWjBaMQswCQYDVQQGEwJFRTEQMA4GA1UEBxMHVGFsbGlubjEb\nMBkGA1UEChMSU0sgSUQgU29sdXRpb25zIEFTMRwwGgYDVQQDExNycC1hcGkuc21h\ncnQtaWQuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuycMJZaS\nlaHLAYvqSFLoTZUF61EPr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ugakJZkNo4e0YUAAAFuJnDpmQAABAMARzBFAiBOZX5E\noZTVzSXTZFgxNf16qm8UJz2h3ipNicc3Jk7T5gIhALLh+P1hMSmN+GZ6j2Q0Ithd\n0XCzzLyepocD9MoS5lGgAHYAh3W/51l8+IxDmV+9827/Vo1HVjb/SrVgwbTq/16g\ngw8AAAFuJnDp9wAABAMARzBFAiARiorj+Iahj3ht/QurQ8jhKY3G2gSTpLifh6YW\nw+I+egIhAIQCtaaIjKXP5a8jJbKSphUVmj0f78wX0F3flqSOqbyBAHUARJRlLrDu\nzq/EQAfYqP4owNrmgr7YyzG1P9MzlrW2gagAAAFuJnDpAAAABAMARjBEAiBnqbvU\n9b50/orscwLl8Ynyggfym7rsnfX4zkbq/Iun0gIgG1ar0X2/vLa7PKlgCWmnzNM1\nfM2ex6zBYjjBHNjN5GAwDQYJKoZIhvcNAQELBQADggEBACko+lWd1cqdlSv2GDU2\nFJC6f3rMLOcUr/H6A6taaThUQ9gJ1W/xtlSAldHkwC/X2J9Zuw3MbKn+jV17SFEg\nlWu4iMlOSd5RPM51Dc7DyALAceau/I5rchKrYH3hhspJydZhz1ghgyZ3mdwkQE6t\nYv5v+G4jeHwUXxJ5dFFnRLNCHeTDqpa2zOglA/ORRM83NDt4cKTl3CqXWeeteFyu\nulnrt7w+IuCVhV6zywolQsqI5T77nQ4GfB6Cco3s01JWTaOg+DcPnobjwqk0o0mi\n/rBcmf49zy9T5O8CW6sABOqRV7RKIRSPEiv3M9IKJd621F/OfgGYwWDepBIk4ex3\ndgE=\n-----END CERTIFICATE-----\n";

Expand Down
18 changes: 15 additions & 3 deletions src/test/java/ee/sk/smartid/rest/SmartIdRestIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,19 @@
import java.util.Collections;
import java.util.concurrent.TimeUnit;

import static ee.sk.test.smartid.integration.SmartIdIntegrationTest.TEST_AGAINST_SMART_ID_DEMO;
import static java.util.Arrays.asList;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.junit.Assume.assumeTrue;

public class SmartIdRestIntegrationTest {

private static final String RELYING_PARTY_UUID = "00000000-0000-0000-0000-000000000000";
private static final String RELYING_PARTY_NAME = "DEMO";
private static final String DOCUMENT_NUMBER = "PNOEE-30303039914-5QSV-Q";
private static final String DOCUMENT_NUMBER = "PNOLT-30303039903-FMB7-Q";
private static final String DOCUMENT_NUMBER_LT = "PNOLT-30303039914-PBZK-Q";
private static final String DATA_TO_SIGN = "Hello World!";
private static final String CERTIFICATE_LEVEL_QUALIFIED = "QUALIFIED";
Expand All @@ -54,6 +58,9 @@ public class SmartIdRestIntegrationTest {
@Before
public void setUp() {
connector = new SmartIdRestConnector("https://sid.demo.sk.ee/smart-id-rp/v2/");

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

@Test
Expand Down Expand Up @@ -93,12 +100,13 @@ public void authenticate_withDocumentNumber() throws Exception {

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

assertNotNull(sessionStatus.getResult());
assertThat(sessionStatus.getResult().getEndResult(), is("OK"));
assertThat(sessionStatus.getInteractionFlowUsed(), is("displayTextAndPIN"));

assertAuthenticationResponseCreated(sessionStatus);
}


@Test
public void authenticate_withDocumentNumber_advancedInteraction() throws Exception {
AuthenticationSessionRequest authenticationSessionRequest = new AuthenticationSessionRequest();
Expand All @@ -119,6 +127,8 @@ public void authenticate_withDocumentNumber_advancedInteraction() throws Excepti

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

assertNotNull(sessionStatus.getResult());
assertThat(sessionStatus.getResult().getEndResult(), is("OK"));
org.hamcrest.MatcherAssert.assertThat(sessionStatus.getInteractionFlowUsed(), is("confirmationMessage"));

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

assertNotNull(sessionStatus.getResult());
assertThat(sessionStatus.getResult().getEndResult(), is("OK"));
assertThat(sessionStatus.getInteractionFlowUsed(), is("displayTextAndPIN"));


Expand Down
25 changes: 14 additions & 11 deletions src/test/java/ee/sk/test/smartid/integration/ReadmeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import java.util.Optional;
import java.util.concurrent.TimeUnit;

import static ee.sk.test.smartid.integration.SmartIdIntegrationTest.TEST_AGAINST_SMART_ID_DEMO;
import static java.util.Arrays.asList;
import static org.junit.Assume.assumeTrue;

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

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

/*
Expand Down Expand Up @@ -176,11 +180,10 @@ public void documentConfigureTheClient_feedSeparately() {

@Test
public void documentAuthenticatingWithSemanticsIdentifier() {

SemanticsIdentifier semanticsIdentifier = new SemanticsIdentifier(
SemanticsIdentifier.IdentityType.PNO, // 3 character identity type (PAS-passport, IDC-national identity card or PNO - (national) personal number)
SemanticsIdentifier.CountryCode.EE, // 2 character ISO 3166-1 alpha-2 country code
"30303039914"); // identifier (according to country and identity type reference)
SemanticsIdentifier.CountryCode.LT, // 2 character ISO 3166-1 alpha-2 country code
"30303039903"); // identifier (according to country and identity type reference)

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

SmartIdAuthenticationResponse authenticationResponse = client
.createAuthentication()
.withDocumentNumber("PNOEE-30303039914-5QSV-Q")
.withDocumentNumber("PNOEE-30303039903-1DNH-Q")
.withAuthenticationHash(authenticationHash)
.withCertificateLevel("QUALIFIED")
.withAllowedInteractionsOrder(Collections.singletonList(
Expand Down Expand Up @@ -294,7 +297,7 @@ public void documentObtainingUsersCertificate() {

SmartIdCertificate responseWithSigningCertificate = client
.getCertificate()
.withDocumentNumber("PNOEE-30303039914-5QSV-Q") // returned as authentication result
.withDocumentNumber("PNOEE-30303039903-1DNH-Q") // returned as authentication result
.withCertificateLevel("QUALIFIED")
.fetch();

Expand Down Expand Up @@ -340,7 +343,7 @@ public void documentCreatingSignature() {

SmartIdSignature smartIdSignature = client
.createSignature()
.withDocumentNumber("PNOEE-30303039914-5QSV-Q") // returned as authentication result
.withDocumentNumber("PNOLT-30303039914-PBZK-Q") // returned as authentication result
.withSignableHash(hashToSign)
.withCertificateLevel("QUALIFIED")
.withAllowedInteractionsOrder(asList(
Expand Down Expand Up @@ -389,7 +392,7 @@ public void documentCreatingSignature() {
public void documentInteractionOrderMostCommon() {
SmartIdSignature smartIdSignature = client
.createSignature()
.withDocumentNumber("PNOEE-30303039914-5QSV-Q")
.withDocumentNumber("PNOLT-30303039914-PBZK-Q")
.withSignableHash(hashToSign)
.withCertificateLevel("QUALIFIED")
.withAllowedInteractionsOrder(Collections.singletonList(
Expand All @@ -416,7 +419,7 @@ public void documentInteractionOrderVerificationChoice() {
try {
SmartIdSignature smartIdSignature = client
.createSignature()
.withDocumentNumber("PNOEE-30303039914-5QSV-Q")
.withDocumentNumber("PNOLT-30303039914-PBZK-Q")
.withSignableHash(hashToSign)
.withCertificateLevel("QUALIFIED")
.withAllowedInteractionsOrder(Arrays.asList(
Expand Down Expand Up @@ -444,7 +447,7 @@ public void documentInteractionOrderVerificationChoice() {
public void documentInteractionOrderConfirmationWithFallbackToPin() {
SmartIdSignature smartIdSignature = client
.createSignature()
.withDocumentNumber("PNOEE-30303039914-5QSV-Q")
.withDocumentNumber("PNOLT-30303039914-PBZK-Q") //
.withSignableHash(hashToSign)
.withCertificateLevel("QUALIFIED")
.withAllowedInteractionsOrder(asList(
Expand Down Expand Up @@ -476,7 +479,7 @@ else if (InteractionFlow.DISPLAY_TEXT_AND_PIN.is(smartIdSignature.getInteraction
public void documentInteractionOrder2() {
SmartIdSignature smartIdSignature = client
.createSignature()
.withDocumentNumber("PNOEE-30303039914-5QSV-Q")
.withDocumentNumber("PNOEE-30303039903-1DNH-Q")
.withSignableHash(hashToSign)
.withCertificateLevel("QUALIFIED")
.withAllowedInteractionsOrder(asList(
Expand Down Expand Up @@ -512,7 +515,7 @@ public void documentInteractionOrderWithoutFallback() {
try {
client
.createSignature()
.withDocumentNumber("PNOEE-30303039914-5QSV-Q")
.withDocumentNumber("PNOLT-30303039914-PBZK-Q")
.withSignableHash(hashToSign)
.withCertificateLevel("QUALIFIED")
.withAllowedInteractionsOrder(Collections.singletonList(
Expand Down
Loading

0 comments on commit bbbf783

Please sign in to comment.