Skip to content

Commit c460ded

Browse files
Hotfix/tx code description (#183)
* don't add tx code description * update version and changelog * test * test
1 parent 513e0ad commit c460ded

File tree

9 files changed

+129
-58
lines changed

9 files changed

+129
-58
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
8+
## [v2.1.2](https://github.com/in2workspace/in2-issuer-api/releases/tag/v2.1.2)
9+
### Changed
10+
- Don't include tx code description i preauthorized code response.
11+
12+
713
## [v2.1.1](https://github.com/in2workspace/in2-issuer-api/releases/tag/v2.1.1)
814
### Added
915
- Get default language from configuration, use it to translate messages (emails, PIN description).

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ plugins {
1212

1313
group = 'es.in2'
1414

15-
version = '2.1.1'
15+
version = '2.1.2'
1616

1717
java {
1818
sourceCompatibility = '17'

src/main/java/es/in2/issuer/backend/oidc4vci/domain/service/impl/PreAuthorizedCodeServiceImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ private Mono<String> generateTxCode() {
7171
}
7272

7373
private Mono<PreAuthorizedCodeResponse> buildPreAuthorizedCodeResponse(String preAuthorizedCode, String txCode) {
74-
String txCodeDescription = translationService.translate(TX_CODE_DESCRIPTION);
75-
Grants.TxCode grantTxCode = new Grants.TxCode(TX_CODE_SIZE, TX_INPUT_MODE, txCodeDescription);
74+
Grants.TxCode grantTxCode = Grants.TxCode.builder()
75+
.length(TX_CODE_SIZE)
76+
.inputMode(TX_INPUT_MODE)
77+
.build();
7678
Grants grants = new Grants(preAuthorizedCode, grantTxCode);
7779
return Mono.just(new PreAuthorizedCodeResponse(grants, txCode));
7880
}

src/main/java/es/in2/issuer/backend/oidc4vci/domain/util/Constants.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ private Constants() {
77
}
88

99
public static final int TX_CODE_SIZE = 4;
10-
public static final String TX_CODE_DESCRIPTION =
11-
"tx-code.description";
1210
public static final String TX_INPUT_MODE = "numeric";
1311
public static final long ACCESS_TOKEN_EXPIRATION_TIME_DAYS = 30L;
1412
}

src/main/java/es/in2/issuer/backend/shared/domain/model/dto/Grants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public record Grants(
1515
public record TxCode(
1616
@JsonProperty("length") int length,
1717
@JsonProperty("input_mode") String inputMode,
18+
//todo consider removing this field
1819
@JsonProperty("description") String description
1920
) {
2021
}

src/main/resources/messages/messages.properties

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,4 @@ email.credential-ready=Credential ready
1010
email.unsuccessful-submission = Certification Submission to Marketplace Unsuccessful
1111
email.missing-documents-certification = Missing Documents for Certification
1212
email.default-status.subject = Credential Notification
13-
email.you-can-use-wallet = You can now use it with your wallet.
14-
15-
tx-code.description = A PIN has been sent to your email. Check your inbox. Enter your PIN Code.
13+
email.you-can-use-wallet = You can now use it with your wallet.

src/main/resources/messages/messages_es.properties

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,4 @@ email.credential-ready=Credencial lista
1010
email.unsuccessful-submission = Error al enviar la certificación al Marketplace
1111
email.missing-documents-certification = Faltan documentos para la certificación
1212
email.default-status.subject = Notificación sobre Credencial
13-
email.you-can-use-wallet = Ya puedes usarla con el wallet.
14-
15-
tx-code.description = Se ha enviado un código PIN a tu email. Consulta tu bandeja de entrada. Introduce el PIN.
13+
email.you-can-use-wallet = Ya puedes usarla con el wallet.

src/test/java/es/in2/issuer/backend/oidc4vci/domain/service/PreAuthorizedCodeServiceTest.java

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package es.in2.issuer.backend.oidc4vci.domain.service.impl;
2+
3+
import es.in2.issuer.backend.shared.domain.model.dto.CredentialProcedureIdAndTxCode;
4+
import es.in2.issuer.backend.shared.domain.model.dto.Grants;
5+
import es.in2.issuer.backend.shared.domain.model.dto.PreAuthorizedCodeResponse;
6+
import es.in2.issuer.backend.shared.domain.service.TranslationService;
7+
import es.in2.issuer.backend.shared.infrastructure.repository.CacheStore;
8+
import org.junit.jupiter.api.BeforeEach;
9+
import org.junit.jupiter.api.Test;
10+
import org.junit.jupiter.api.extension.ExtendWith;
11+
import org.mockito.Mock;
12+
import org.mockito.junit.jupiter.MockitoExtension;
13+
import reactor.core.publisher.Mono;
14+
import reactor.test.StepVerifier;
15+
16+
import java.lang.reflect.Method;
17+
import java.security.SecureRandom;
18+
19+
import static es.in2.issuer.backend.oidc4vci.domain.util.Constants.TX_CODE_SIZE;
20+
import static es.in2.issuer.backend.oidc4vci.domain.util.Constants.TX_INPUT_MODE;
21+
import static org.junit.jupiter.api.Assertions.*;
22+
23+
@ExtendWith(MockitoExtension.class)
24+
class PreAuthorizedCodeServiceImplTest {
25+
26+
@Mock
27+
private SecureRandom random; // Unused in these tests, needed by constructor
28+
@Mock
29+
private CacheStore<CredentialProcedureIdAndTxCode> cacheStore; // Unused here
30+
@Mock
31+
private TranslationService translationService; // Unused here
32+
33+
private PreAuthorizedCodeServiceImpl service;
34+
35+
@BeforeEach
36+
void setUp() {
37+
service = new PreAuthorizedCodeServiceImpl(random, cacheStore, translationService);
38+
}
39+
40+
@Test
41+
void buildPreAuthorizedCodeResponse_createsExpectedPayload() throws Exception {
42+
// Given
43+
String preAuthorizedCode = "pre-auth-abc123";
44+
String txCode = "567890";
45+
46+
// When
47+
Mono<PreAuthorizedCodeResponse> mono = invokeBuild(preAuthorizedCode, txCode);
48+
49+
// Then
50+
StepVerifier.create(mono)
51+
.assertNext(resp -> {
52+
assertNotNull(resp, "Response must not be null");
53+
// PreAuthorizedCodeResponse(pin=..., grants=...)
54+
assertEquals(txCode, resp.pin(), "pin in response must match input txCode");
55+
56+
Grants grants = resp.grants();
57+
assertNotNull(grants, "grants must not be null");
58+
assertEquals(preAuthorizedCode, grants.preAuthorizedCode(),
59+
"preAuthorizedCode in grants must match input");
60+
61+
Grants.TxCode grantTx = grants.txCode();
62+
assertNotNull(grantTx, "grants.txCode must not be null");
63+
assertEquals(TX_CODE_SIZE, grantTx.length(),
64+
"TxCode.length must match TX_CODE_SIZE");
65+
assertEquals(TX_INPUT_MODE, grantTx.inputMode(),
66+
"TxCode.inputMode must match TX_INPUT_MODE");
67+
// Not set in service; should be null
68+
assertNull(grantTx.description(), "TxCode.description should be null");
69+
})
70+
.verifyComplete();
71+
}
72+
73+
@Test
74+
void buildPreAuthorizedCodeResponse_emitsSingleValueAndCompletes() throws Exception {
75+
// Given
76+
String preAuthorizedCode = "pre-auth-xyz789";
77+
String txCode = "123456";
78+
79+
// When
80+
Mono<PreAuthorizedCodeResponse> mono = invokeBuild(preAuthorizedCode, txCode);
81+
82+
// Then
83+
StepVerifier.create(mono)
84+
.expectNextCount(1)
85+
.verifyComplete();
86+
}
87+
88+
// --- Helper to call the private method via reflection ---
89+
90+
@SuppressWarnings("unchecked")
91+
private Mono<PreAuthorizedCodeResponse> invokeBuild(String preAuthorizedCode, String txCode) throws Exception {
92+
Method m = PreAuthorizedCodeServiceImpl.class
93+
.getDeclaredMethod("buildPreAuthorizedCodeResponse", String.class, String.class);
94+
m.setAccessible(true);
95+
return (Mono<PreAuthorizedCodeResponse>) m.invoke(service, preAuthorizedCode, txCode);
96+
}
97+
98+
@Test
99+
void buildPreAuthorizedCodeResponse_shouldBuildTxCodeProperly() throws Exception {
100+
// Given
101+
String preAuthorizedCode = "pre-auth-sonar";
102+
String txCode = "999999";
103+
104+
// When
105+
Mono<PreAuthorizedCodeResponse> mono = invokeBuild(preAuthorizedCode, txCode);
106+
PreAuthorizedCodeResponse response = mono.block(); // Forces execution of Mono.just(...)
107+
108+
// Then
109+
assertNotNull(response, "Response must not be null");
110+
Grants.TxCode grantTx = response.grants().txCode();
111+
assertNotNull(grantTx, "TxCode must not be null");
112+
assertEquals(TX_CODE_SIZE, grantTx.length(), "Should match TX_CODE_SIZE constant");
113+
assertEquals(TX_INPUT_MODE, grantTx.inputMode(), "Should match TX_INPUT_MODE constant");
114+
}
115+
}

0 commit comments

Comments
 (0)