-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk): added company id and name in activity log list (#65)
- Loading branch information
1 parent
d2f5924
commit 6cccaaf
Showing
16 changed files
with
505 additions
and
151 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...-java-sdk-auth/src/main/java/com/consoleconnect/kraken/operator/auth/dto/JwtTokenDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.consoleconnect.kraken.operator.auth.dto; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class JwtTokenDto { | ||
private Header header; | ||
private Payload payload; | ||
|
||
@Data | ||
public static class Header { | ||
private String kid; | ||
private String alg; | ||
} | ||
|
||
@Data | ||
public static class Payload { | ||
private String sub; | ||
private String iat; | ||
private String exp; | ||
private String iss; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -427,7 +427,7 @@ void givenUserCreated_whenSearch_thenReturnOk() { | |
Assertions.assertNotNull(bodyStr); | ||
assertThat(bodyStr, hasJsonPath("$.data.data", notNullValue())); | ||
assertThat(bodyStr, hasJsonPath("$.data.data", hasSize(greaterThanOrEqualTo(1)))); | ||
assertThat(bodyStr, hasJsonPath("$.data.data[0].email", is("[email protected]"))); | ||
assertThat(bodyStr, hasJsonPath("$.data.data[0].email", equalTo("[email protected]"))); | ||
}); | ||
} | ||
|
||
|
39 changes: 39 additions & 0 deletions
39
...h/src/test/java/com/consoleconnect/kraken/operator/auth/helper/JwtDecoderToolkitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.consoleconnect.kraken.operator.auth.helper; | ||
|
||
import com.consoleconnect.kraken.operator.auth.dto.JwtTokenDto; | ||
import com.consoleconnect.kraken.operator.auth.jwt.JwtDecoderToolkit; | ||
import java.util.Optional; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
@Slf4j | ||
class JwtDecoderToolkitTest { | ||
public static String[] illegalDataSetForDecoding() { | ||
return new String[] {"", " ", "xxswewwew.sssss", "xxswewwew"}; | ||
} | ||
|
||
public static String[] legalDataSetForDecoding() { | ||
return new String[] { | ||
"bearer eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJ0ZXN0LXN1YmplY3QiLCJzY3AiOlsibWVzc2FnZTpyZWFkIl0sImV4cCI6NDY4Mzg5Nzc3Nn0.LtMVtIiRIwSyc3aX35Zl0JVwLTcQZAB3dyBOMHNaHCKUljwMrf20a_gT79LfhjDzE_fUVUmFiAO32W1vFnYpZSVaMDUgeIOIOpxfoe9shj_uYenAwIS-_UxqGVIJiJoXNZh_MK80ShNpvsQwamxWEEOAMBtpWNiVYNDMdfgho9n3o5_Z7Gjy8RLBo1tbDREbO9kTFwGIxm_EYpezmRCRq4w1DdS6UDW321hkwMxPnCMSWOvp-hRpmgY2yjzLgPJ6Aucmg9TJ8jloAP1DjJoF1gRR7NTAk8LOGkSjTzVYDYMbCF51YdpojhItSk80YzXiEsv1mTz4oMM49jXBmfXFMA", | ||
"bearer eyJhbGciOiJSUzUxMiJ9.eyJzdWIiOiJ0ZXN0LXN1YmplY3QiLCJleHAiOjE5NzQzMjYxMTl9.LKAx-60EBfD7jC1jb1eKcjO4uLvf3ssISV-8tN-qp7gAjSvKvj4YA9-V2mIb6jcS1X_xGmNy6EIimZXpWaBR3nJmeu-jpe85u4WaW2Ztr8ecAi-dTO7ZozwdtljKuBKKvj4u1nF70zyCNl15AozSG0W1ASrjUuWrJtfyDG6WoZ8VfNMuhtU-xUYUFvscmeZKUYQcJ1KS-oV5tHeF8aNiwQoiPC_9KXCOZtNEJFdq6-uzFdHxvOP2yex5Gbmg5hXonauIFXG2ZPPGdXzm-5xkhBpgM8U7A_6wb3So8wBvLYYm2245QUump63AJRAy8tQpwt4n9MvQxQgS3z9R-NK92A" | ||
}; | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource(value = "illegalDataSetForDecoding") | ||
void givenIllegalToken_whenDecode_thenReturnEmpty(String token) { | ||
Optional<JwtTokenDto> result = JwtDecoderToolkit.decodeJWTToken(token); | ||
Assertions.assertTrue(result.isEmpty()); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource(value = "legalDataSetForDecoding") | ||
void givenLegalJwtToken_whenDecode_thenReturnOK(String token) { | ||
Optional<JwtTokenDto> result = JwtDecoderToolkit.decodeJWTToken(token); | ||
Assertions.assertTrue(result.isPresent()); | ||
Assertions.assertNotNull(result.get().getHeader()); | ||
Assertions.assertNotNull(result.get().getPayload()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...er/src/test/java/com/consoleconnect/kraken/operator/controller/ApiActivityLogCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.consoleconnect.kraken.operator.controller; | ||
|
||
import com.consoleconnect.kraken.operator.core.entity.ApiActivityLogEntity; | ||
import com.consoleconnect.kraken.operator.core.repo.ApiActivityLogRepository; | ||
import com.google.common.collect.Maps; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
public interface ApiActivityLogCreator { | ||
|
||
ApiActivityLogRepository getApiActivityLogRepository(); | ||
|
||
default ApiActivityLogEntity createApiActivityLog(String buyerId, String envId) { | ||
ApiActivityLogEntity apiActivityLogEntity = new ApiActivityLogEntity(); | ||
apiActivityLogEntity.setRequestId(UUID.randomUUID().toString()); | ||
apiActivityLogEntity.setPath("/123"); | ||
apiActivityLogEntity.setUri("localhost"); | ||
apiActivityLogEntity.setMethod("GET"); | ||
apiActivityLogEntity.setEnv(envId); | ||
Map<String, String> headers = Maps.newHashMap(); | ||
headers.put("acces_token", "2334"); | ||
apiActivityLogEntity.setHeaders(headers); | ||
apiActivityLogEntity.setBuyer(buyerId); | ||
apiActivityLogEntity.setCallSeq(0); | ||
apiActivityLogEntity = getApiActivityLogRepository().save(apiActivityLogEntity); | ||
return apiActivityLogEntity; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...-controller/src/test/java/com/consoleconnect/kraken/operator/controller/BuyerCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.consoleconnect.kraken.operator.controller; | ||
|
||
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
|
||
import com.consoleconnect.kraken.operator.controller.dto.BuyerAssetDto; | ||
import com.consoleconnect.kraken.operator.controller.dto.CreateBuyerRequest; | ||
import com.consoleconnect.kraken.operator.core.model.HttpResponse; | ||
import com.consoleconnect.kraken.operator.core.toolkit.JsonToolkit; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.HttpStatus; | ||
|
||
public interface BuyerCreator { | ||
String PRODUCT_ID = "product.mef.sonata.api"; | ||
String BUYER_BASE_URL = String.format("/products/%s/buyers", PRODUCT_ID); | ||
String BUYER_ID = "testing-company"; | ||
String COMPANY_NAME = "testing-company-name"; | ||
|
||
WebTestClientHelper getWebTestClient(); | ||
|
||
default BuyerAssetDto createBuyer(String buyerId, String envId, String companyName) { | ||
CreateBuyerRequest requestEntity = new CreateBuyerRequest(); | ||
requestEntity.setBuyerId(buyerId); | ||
requestEntity.setEnvId(envId); | ||
requestEntity.setCompanyName(companyName); | ||
|
||
String resp = | ||
getWebTestClient() | ||
.requestAndVerify( | ||
HttpMethod.POST, | ||
uriBuilder -> uriBuilder.path(BUYER_BASE_URL).build(), | ||
HttpStatus.OK.value(), | ||
requestEntity, | ||
bodyStr -> { | ||
assertThat(bodyStr, hasJsonPath("$.data", notNullValue())); | ||
assertThat(bodyStr, hasJsonPath("$.data.buyerToken", notNullValue())); | ||
assertThat(bodyStr, hasJsonPath("$.data.buyerToken.accessToken", notNullValue())); | ||
}); | ||
HttpResponse<BuyerAssetDto> buyerCreatedResp = | ||
JsonToolkit.fromJson(resp, new TypeReference<HttpResponse<BuyerAssetDto>>() {}); | ||
return buyerCreatedResp.getData(); | ||
} | ||
} |
Oops, something went wrong.