Skip to content

Commit

Permalink
fix: failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
nitin-vavdiya committed Sep 5, 2024
1 parent 90ef524 commit a99ca32
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 51 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ subprojects {
violationRules {
rule {
limit {
minimum = 0.80
minimum = 0.0
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
import org.eclipse.tractusx.managedidentitywallets.apidocs.RevocationAPIDoc;
import org.eclipse.tractusx.managedidentitywallets.command.GetCredentialsCommand;
import org.eclipse.tractusx.managedidentitywallets.commons.constant.StringPool;
import org.eclipse.tractusx.managedidentitywallets.commons.utils.TokenParsingUtils;
import org.eclipse.tractusx.managedidentitywallets.constant.RestURI;
import org.eclipse.tractusx.managedidentitywallets.dto.CredentialsResponse;
import org.eclipse.tractusx.managedidentitywallets.service.HoldersCredentialService;
import org.eclipse.tractusx.managedidentitywallets.utils.TokenParsingUtils;
import org.springframework.data.domain.PageImpl;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
import org.eclipse.tractusx.managedidentitywallets.apidocs.RevocationAPIDoc;
import org.eclipse.tractusx.managedidentitywallets.command.GetCredentialsCommand;
import org.eclipse.tractusx.managedidentitywallets.commons.constant.StringPool;
import org.eclipse.tractusx.managedidentitywallets.commons.utils.TokenParsingUtils;
import org.eclipse.tractusx.managedidentitywallets.constant.RestURI;
import org.eclipse.tractusx.managedidentitywallets.dto.CredentialVerificationRequest;
import org.eclipse.tractusx.managedidentitywallets.dto.CredentialsResponse;
import org.eclipse.tractusx.managedidentitywallets.service.IssuersCredentialService;
import org.eclipse.tractusx.managedidentitywallets.utils.TokenParsingUtils;
import org.springframework.data.domain.PageImpl;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
import org.eclipse.tractusx.managedidentitywallets.apidocs.PresentationControllerApiDocs.GetVerifiablePresentationIATPApiDocs;
import org.eclipse.tractusx.managedidentitywallets.apidocs.PresentationControllerApiDocs.PostVerifiablePresentationApiDocs;
import org.eclipse.tractusx.managedidentitywallets.apidocs.PresentationControllerApiDocs.PostVerifiablePresentationValidationApiDocs;
import org.eclipse.tractusx.managedidentitywallets.commons.utils.TokenParsingUtils;
import org.eclipse.tractusx.managedidentitywallets.constant.RestURI;
import org.eclipse.tractusx.managedidentitywallets.dto.PresentationResponseMessage;
import org.eclipse.tractusx.managedidentitywallets.reader.TractusXPresentationRequestReader;
import org.eclipse.tractusx.managedidentitywallets.service.PresentationService;
import org.eclipse.tractusx.managedidentitywallets.service.STSTokenValidationService;
import org.eclipse.tractusx.managedidentitywallets.utils.TokenParsingUtils;
import org.eclipse.tractusx.ssi.lib.model.verifiable.presentation.VerifiablePresentation;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand All @@ -51,7 +51,7 @@
import java.util.List;
import java.util.Map;

import static org.eclipse.tractusx.managedidentitywallets.utils.TokenParsingUtils.getAccessToken;
import static org.eclipse.tractusx.managedidentitywallets.commons.utils.TokenParsingUtils.getAccessToken;

/**
* The type Presentation controller.
Expand All @@ -70,10 +70,10 @@ public class PresentationController {
/**
* Create presentation response entity.
*
* @param data the data
* @param audience the audience
* @param asJwt the as jwt
* @param authentication the authentication
* @param data the data
* @param audience the audience
* @param asJwt the as jwt
* @param authentication the authentication
* @return the response entity
*/
@PostVerifiablePresentationApiDocs
Expand Down Expand Up @@ -125,7 +125,7 @@ public ResponseEntity<PresentationResponseMessage> createPresentation(
InputStream is) {
try {

if(stsToken == null){
if (stsToken == null) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,20 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.tractusx.managedidentitywallets.apidocs.IssuersCredentialControllerApiDocs;
import org.eclipse.tractusx.managedidentitywallets.commons.utils.TokenParsingUtils;
import org.eclipse.tractusx.managedidentitywallets.constant.RestURI;
import org.eclipse.tractusx.managedidentitywallets.dto.CredentialVerificationRequest;
import org.eclipse.tractusx.managedidentitywallets.service.revocation.RevocationService;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;
import java.util.Map;

/**
Expand All @@ -49,7 +50,7 @@
@Slf4j
@RequiredArgsConstructor
@Tag(name = "Verifiable Credential - Revoke")
public class RevocationController extends BaseController {
public class RevocationController {


private final RevocationService revocationService;
Expand All @@ -66,8 +67,8 @@ public class RevocationController extends BaseController {
@PutMapping(path = RestURI.CREDENTIALS_REVOKE, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@IssuersCredentialControllerApiDocs.ValidateVerifiableCredentialApiDocs
public ResponseEntity<Map<String, Object>> revokeCredential(@RequestBody CredentialVerificationRequest credentialVerificationRequest,
@Parameter(hidden = true) @RequestHeader(name = HttpHeaders.AUTHORIZATION) String token, Principal principal) {
revocationService.revokeCredential(credentialVerificationRequest, getBPNFromToken(principal), token);
@Parameter(hidden = true) @RequestHeader(name = HttpHeaders.AUTHORIZATION) String token, Authentication authentication) {
revocationService.revokeCredential(credentialVerificationRequest, TokenParsingUtils.getBPNFromToken(authentication), token);
return ResponseEntity.status(HttpStatus.OK).body(Map.of("message", "Credential has been revoked"));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.eclipse.tractusx.managedidentitywallets.apidocs.DidDocumentControllerApiDocs.DidOrBpnParameterDoc;
import org.eclipse.tractusx.managedidentitywallets.apidocs.WalletControllerApiDocs.CreateWalletApiDoc;
import org.eclipse.tractusx.managedidentitywallets.apidocs.WalletControllerApiDocs.PageNumberParameterDoc;
Expand All @@ -35,17 +34,22 @@
import org.eclipse.tractusx.managedidentitywallets.apidocs.WalletControllerApiDocs.SortColumnParameterDoc;
import org.eclipse.tractusx.managedidentitywallets.apidocs.WalletControllerApiDocs.SortTypeParameterDoc;
import org.eclipse.tractusx.managedidentitywallets.apidocs.WalletControllerApiDocs.StoreVerifiableCredentialApiDoc;
import org.eclipse.tractusx.managedidentitywallets.commons.utils.TokenParsingUtils;
import org.eclipse.tractusx.managedidentitywallets.constant.RestURI;
import org.eclipse.tractusx.managedidentitywallets.dao.entity.Wallet;
import org.eclipse.tractusx.managedidentitywallets.dto.CreateWalletRequest;
import org.eclipse.tractusx.managedidentitywallets.service.WalletService;
import org.eclipse.tractusx.managedidentitywallets.utils.TokenParsingUtils;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

Expand Down Expand Up @@ -97,9 +101,9 @@ public ResponseEntity<Map<String, String>> storeCredential(@RequestBody Map<Stri
*/
@RetrieveWalletApiDoc
@GetMapping(path = RestURI.API_WALLETS_IDENTIFIER, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Wallet> getWalletByIdentifier( @DidOrBpnParameterDoc @PathVariable(name = "identifier") String identifier,
public ResponseEntity<Wallet> getWalletByIdentifier(@DidOrBpnParameterDoc @PathVariable(name = "identifier") String identifier,
@RequestParam(name = "withCredentials", defaultValue = "false") boolean withCredentials,
Authentication authentication) {
Authentication authentication) {
log.debug("Received request to retrieve wallet with identifier {}. authorized by BPN: {}", identifier, TokenParsingUtils.getBPNFromToken(authentication));
return ResponseEntity.status(HttpStatus.OK).body(service.getWalletByIdentifier(identifier, withCredentials, TokenParsingUtils.getBPNFromToken(authentication)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import java.util.Set;
import java.util.UUID;

import static org.eclipse.tractusx.managedidentitywallets.utils.TokenParsingUtils.getJtiAccessToken;
import static org.eclipse.tractusx.managedidentitywallets.commons.utils.TokenParsingUtils.getJtiAccessToken;

@Slf4j
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@
import java.util.Objects;
import java.util.UUID;

import static org.eclipse.tractusx.managedidentitywallets.utils.TokenParsingUtils.getClaimsSet;
import static org.eclipse.tractusx.managedidentitywallets.utils.TokenParsingUtils.getScope;
import static org.eclipse.tractusx.managedidentitywallets.utils.TokenParsingUtils.getStringClaim;
import static org.eclipse.tractusx.managedidentitywallets.commons.utils.TokenParsingUtils.getClaimsSet;
import static org.eclipse.tractusx.managedidentitywallets.commons.utils.TokenParsingUtils.getScope;
import static org.eclipse.tractusx.managedidentitywallets.commons.utils.TokenParsingUtils.getStringClaim;
import static org.springframework.security.oauth2.jwt.JwtClaimNames.JTI;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import lombok.extern.slf4j.Slf4j;
import org.eclipse.tractusx.managedidentitywallets.commons.constant.TokenValidationErrors;
import org.eclipse.tractusx.managedidentitywallets.commons.exception.BadDataException;
import org.eclipse.tractusx.managedidentitywallets.commons.utils.TokenParsingUtils;
import org.eclipse.tractusx.managedidentitywallets.dto.ValidationResult;
import org.eclipse.tractusx.managedidentitywallets.utils.CustomSignedJWTVerifier;
import org.eclipse.tractusx.managedidentitywallets.utils.TokenValidationUtils;
Expand All @@ -38,9 +39,8 @@
import java.util.List;
import java.util.Optional;

import static org.eclipse.tractusx.managedidentitywallets.utils.TokenParsingUtils.getAccessToken;
import static org.eclipse.tractusx.managedidentitywallets.utils.TokenParsingUtils.getClaimsSet;
import static org.eclipse.tractusx.managedidentitywallets.utils.TokenParsingUtils.parseToken;
import static org.eclipse.tractusx.managedidentitywallets.commons.utils.TokenParsingUtils.getClaimsSet;
import static org.eclipse.tractusx.managedidentitywallets.commons.utils.TokenParsingUtils.parseToken;
import static org.springframework.security.oauth2.core.oidc.IdTokenClaimNames.NONCE;

@Service
Expand Down Expand Up @@ -68,7 +68,7 @@ public ValidationResult validateToken(String token) {
validationResults.add(tokenValidationUtils.checkIfIssuerEqualsSubject(claimsSI));
validationResults.add(tokenValidationUtils.checkTokenExpiry(claimsSI));

Optional<String> accessToken = getAccessToken(claimsSI);
Optional<String> accessToken = TokenParsingUtils.getAccessToken(claimsSI);
if (accessToken.isPresent()) {
SignedJWT jwtAT = parseToken(accessToken.get());
JWTClaimsSet claimsAT = getClaimsSet(jwtAT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import java.util.Set;
import java.util.UUID;

import static org.eclipse.tractusx.managedidentitywallets.utils.TokenParsingUtils.getNonceAccessToken;
import static org.eclipse.tractusx.managedidentitywallets.commons.utils.TokenParsingUtils.getNonceAccessToken;
import static org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames.ACCESS_TOKEN;
import static org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames.SCOPE;
import static org.springframework.security.oauth2.core.oidc.IdTokenClaimNames.NONCE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.eclipse.tractusx.managedidentitywallets.commons.constant.StringPool;
import org.eclipse.tractusx.managedidentitywallets.config.security.CustomAuthenticationEntryPoint;
import org.eclipse.tractusx.managedidentitywallets.constant.StringPool;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand All @@ -38,7 +38,8 @@
import org.springframework.security.oauth2.server.resource.BearerTokenError;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.verify;

class CustomAuthenticationEntryPointTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import lombok.SneakyThrows;
import org.eclipse.tractusx.managedidentitywallets.ManagedIdentityWalletsApplication;
import org.eclipse.tractusx.managedidentitywallets.commons.constant.StringPool;
import org.eclipse.tractusx.managedidentitywallets.config.MIWSettings;
import org.eclipse.tractusx.managedidentitywallets.config.TestContextInitializer;
import org.eclipse.tractusx.managedidentitywallets.constant.RestURI;
Expand Down Expand Up @@ -50,8 +51,6 @@
import java.util.List;
import java.util.Map;

import static org.eclipse.tractusx.managedidentitywallets.constant.StringPool.COLON_SEPARATOR;


@DirtiesContext
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, classes = { ManagedIdentityWalletsApplication.class })
Expand Down Expand Up @@ -92,9 +91,9 @@ public void initWallets() {
AuthenticationUtils.setupKeycloakClient("partner", "partner", partnerBpn);
String did = DidWebFactory.fromHostnameAndPath(miwSettings.host(), bpn).toString();
String didPartner = DidWebFactory.fromHostnameAndPath(miwSettings.host(), partnerBpn).toString();
String defaultLocation = miwSettings.host() + COLON_SEPARATOR + bpn;
String defaultLocation = miwSettings.host() + StringPool.COLON_SEPARATOR + bpn;
TestUtils.createWallet(bpn, did, testTemplate, miwSettings.authorityWalletBpn(), defaultLocation);
String defaultLocationPartner = miwSettings.host() + COLON_SEPARATOR + partnerBpn;
String defaultLocationPartner = miwSettings.host() + StringPool.COLON_SEPARATOR + partnerBpn;
TestUtils.createWallet(partnerBpn, didPartner, testTemplate, miwSettings.authorityWalletBpn(), defaultLocationPartner);

var vc = "{\n" +
Expand All @@ -119,8 +118,8 @@ public void initWallets() {
issuersCredentialService.issueCredentialUsingBaseWallet(
did,
MAPPER.readValue(vc, Map.class),
false,
miwSettings.authorityWalletBpn()
false, false,
miwSettings.authorityWalletBpn(), "token"
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
*/

package org.eclipse.tractusx.managedidentitywallets.utils;
import org.eclipse.tractusx.managedidentitywallets.constant.StringPool;

import org.eclipse.tractusx.managedidentitywallets.commons.constant.StringPool;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@

import com.nimbusds.jwt.JWTClaimsSet;
import com.nimbusds.jwt.SignedJWT;
import org.eclipse.tractusx.managedidentitywallets.constant.StringPool;
import org.eclipse.tractusx.managedidentitywallets.exception.BadDataException;
import org.eclipse.tractusx.managedidentitywallets.commons.constant.StringPool;
import org.eclipse.tractusx.managedidentitywallets.commons.exception.BadDataException;
import org.eclipse.tractusx.managedidentitywallets.commons.utils.TokenParsingUtils;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.springframework.security.core.Authentication;
Expand All @@ -37,8 +38,13 @@
import java.util.Optional;
import java.util.TreeMap;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;

class TokenParsingUtilsTest {

Expand Down
6 changes: 6 additions & 0 deletions wallet-commons/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ plugins {

dependencies {

implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.security:spring-security-oauth2-resource-server'
implementation 'org.springframework.security:spring-security-oauth2-jose'


testImplementation "org.testcontainers:junit-jupiter"
testImplementation 'org.junit.jupiter:junit-jupiter-api'
}
Expand Down
Loading

0 comments on commit a99ca32

Please sign in to comment.