Skip to content

Commit 376e0db

Browse files
SK-2071: update unit tests
1 parent cba96c9 commit 376e0db

14 files changed

Lines changed: 682 additions & 65 deletions

File tree

.github/workflows/beta-release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ jobs:
1818
skyflow-credentials: ${{ secrets.SKYFLOW_CREDENTIALS }} >> .env
1919
test-expired-token: ${{ secrets.TEST_EXPIRED_TOKEN }} >> .env
2020
test-reusable-token: ${{ secrets.TEST_REUSABLE_TOKEN }} >> .env
21+
vault-client-creds: ${{ secrets.VAULT_CLIENT_SKYFLOW_CREDENTIALS }} >> .env

.github/workflows/internal-release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ jobs:
2525
skyflow-credentials: ${{ secrets.SKYFLOW_CREDENTIALS }} >> .env
2626
test-expired-token: ${{ secrets.TEST_EXPIRED_TOKEN }} >> .env
2727
test-reusable-token: ${{ secrets.TEST_REUSABLE_TOKEN }} >> .env
28+
vault-client-creds: ${{ secrets.VAULT_CLIENT_SKYFLOW_CREDENTIALS }} >> .env

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
json: ${{ secrets.TEST_CREDENTIALS_FILE_STRING }}
2424

2525
- name: Build & Run tests with Maven
26-
run: mvn -B package -DTEST_VAULT_ID=${{ secrets.TEST_VAULT_ID }} -DTEST_VAULT_URL=${{ secrets.TEST_VAULT_URL }} -DTEST_SKYFLOW_ID=${{ secrets.TEST_SKYFLOW_ID }} -DTEST_TOKEN=${{ secrets.TEST_TOKEN }} -DTEST_CREDENTIALS=${{ secrets.TEST_CREDENTIALS_FILE_STRING }} -DTEST_EXPIRED_TOKEN=${{ secrets.TEST_EXPIRED_TOKEN }} -DTEST_REUSABLE_TOKEN=${{ secrets.TEST_REUSABLE_TOKEN }} -f pom.xml
26+
run: mvn -B package -DTEST_VAULT_ID=${{ secrets.TEST_VAULT_ID }} -DTEST_VAULT_URL=${{ secrets.TEST_VAULT_URL }} -DTEST_SKYFLOW_ID=${{ secrets.TEST_SKYFLOW_ID }} -DTEST_TOKEN=${{ secrets.TEST_TOKEN }} -DTEST_CREDENTIALS=${{ secrets.TEST_CREDENTIALS_FILE_STRING }} -DTEST_EXPIRED_TOKEN=${{ secrets.TEST_EXPIRED_TOKEN }} -DTEST_REUSABLE_TOKEN=${{ secrets.TEST_REUSABLE_TOKEN }} -DVAULT_CLIENT_SKYFLOW_CREDENTIALS=${{ secrets.VAULT_CLIENT_SKYFLOW_CREDENTIALS }} -f pom.xml
2727

2828
- name: Codecov
2929
uses: codecov/codecov-action@v2.1.0

.github/workflows/pr.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jobs:
3838
echo SKYFLOW_CREDENTIALS=${{ secrets.SKYFLOW_CREDENTIALS }} >> .env
3939
echo TEST_EXPIRED_TOKEN=${{ secrets.TEST_EXPIRED_TOKEN }} >> .env
4040
echo TEST_REUSABLE_TOKEN=${{ secrets.TEST_REUSABLE_TOKEN }} >> .env
41+
echo VAULT_CLIENT_SKYFLOW_CREDENTIALS=${{ secrets.VAULT_CLIENT_SKYFLOW_CREDENTIALS }} >> .env
4142
4243
- name: Build & Run tests with Maven
4344
run: mvn -B package -f pom.xml

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ jobs:
1818
skyflow-credentials: ${{ secrets.SKYFLOW_CREDENTIALS }} >> .env
1919
test-expired-token: ${{ secrets.TEST_EXPIRED_TOKEN }} >> .env
2020
test-reusable-token: ${{ secrets.TEST_REUSABLE_TOKEN }} >> .env
21+
vault-client-creds: ${{ secrets.VAULT_CLIENT_SKYFLOW_CREDENTIALS }} >> .env

.github/workflows/shared-build-and-deploy.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ on:
4343
test-reusable-token:
4444
required: true
4545

46+
vault-client-creds:
47+
required: true
48+
4649
jobs:
4750
publish:
4851
runs-on: ubuntu-latest
@@ -116,6 +119,7 @@ jobs:
116119
echo SKYFLOW_CREDENTIALS=${{ secrets.skyflow-credentials }} >> .env
117120
echo TEST_EXPIRED_TOKEN=${{ secrets.test-expired-token }} >> .env
118121
echo TEST_REUSABLE_TOKEN=${{ secrets.test-reusable-token }} >> .env
122+
echo VAULT_CLIENT_SKYFLOW_CREDENTIALS=${{ secrets.vault-client-creds }} >> .env
119123
120124
- name: Create credentials json
121125
id: create-json

src/main/java/com/skyflow/VaultClient.java

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,55 @@ protected DeidentifyDocumentRequest getDeidentifyDocumentRequest(DeidentifyFileR
704704
.build();
705705
}
706706

707-
// Helper method to build TokenType
707+
protected com.skyflow.generated.rest.resources.files.requests.DeidentifyFileRequest getDeidentifyGenericFileRequest(
708+
DeidentifyFileRequest request, String vaultId, String base64Content, String fileExtension) {
709+
710+
List<EntityType> mappedEntityTypes = getEntityTypes(request.getEntities());
711+
712+
TokenFormat tokenFormat = request.getTokenFormat();
713+
714+
Optional<List<EntityType>> entityTypes = Optional.empty();
715+
Optional<List<EntityType>> entityUniqueCounter = Optional.empty();
716+
Optional<List<String>> allowRegex = Optional.ofNullable(request.getAllowRegexList());
717+
Optional<List<String>> restrictRegex = Optional.ofNullable(request.getRestrictRegexList());
718+
Optional<Transformations> transformations = Optional.ofNullable(getTransformations(request.getTransformations()));
719+
720+
if (tokenFormat != null) {
721+
if (tokenFormat.getEntityOnly() != null && !tokenFormat.getEntityOnly().isEmpty()) {
722+
entityTypes = Optional.of(tokenFormat.getEntityOnly().stream()
723+
.map(detectEntity -> EntityType.valueOf(detectEntity.name()))
724+
.collect(Collectors.toList()));
725+
}
726+
727+
if (tokenFormat.getEntityUniqueCounter() != null && !tokenFormat.getEntityUniqueCounter().isEmpty()) {
728+
entityUniqueCounter = Optional.of(tokenFormat.getEntityUniqueCounter().stream()
729+
.map(detectEntity -> EntityType.valueOf(detectEntity.name()))
730+
.collect(Collectors.toList()));
731+
}
732+
}
733+
734+
TokenTypeWithoutVault tokenType = TokenTypeWithoutVault.builder()
735+
.entityOnly(entityTypes)
736+
.entityUnqCounter(entityUniqueCounter)
737+
.build();
738+
739+
DeidentifyFileRequestFile file =
740+
DeidentifyFileRequestFile.builder()
741+
.base64(base64Content)
742+
.dataFormat(fileExtension != null ? DeidentifyFileRequestFileDataFormat.valueOf(fileExtension.toUpperCase()) : null)
743+
.build();
744+
745+
return com.skyflow.generated.rest.resources.files.requests.DeidentifyFileRequest.builder()
746+
.vaultId(vaultId)
747+
.file(file)
748+
.entityTypes(mappedEntityTypes)
749+
.tokenType(tokenType)
750+
.allowRegex(allowRegex)
751+
.restrictRegex(restrictRegex)
752+
.transformations(transformations)
753+
.build();
754+
}
755+
708756
private TokenTypeWithoutVault buildTokenType(TokenFormat tokenFormat,
709757
Optional<List<EntityType>> entityTypes,
710758
Optional<List<EntityType>> entityUniqueCounter) {

src/main/java/com/skyflow/errors/ErrorMessage.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ public enum ErrorMessage {
141141
InvalidWaitTime("%s0 Validation error. The wait time for deidentify file operation should be a positive integer. Specify a valid wait time."),
142142
WaitTimeExceedsLimit("%s0 Validation error. The wait time for deidentify file operation exceeds the maximum limit of 64 seconds. Specify a wait time less than or equal to 60 seconds."),
143143
InvalidOrEmptyRunId("%s0 Validation error. The run ID is invalid or empty. Specify a valid run ID."),
144+
FailedToEncodeFile("%s0 Validation error. Failed to encode the file. Ensure the file is in a supported format and try again."),
145+
PollingForResultsFailed("%s0 API error. Polling for results failed. Unable to retrieve the deidentified file"),
146+
FailedtoSaveProcessedFile("%s0 Validation error. Failed to save the processed file. Ensure the output directory is valid and writable."),
144147
;
145148
private final String message;
146149

src/main/java/com/skyflow/logs/ErrorLogs.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ public enum ErrorLogs {
119119
REIDENTIFY_TEXT_REQUEST_REJECTED("ReIdentify text request resulted in failure."),
120120
DEIDENTIFY_FILE_REQUEST_REJECTED("DeIdentify file request resulted in failure."),
121121
GET_DETECT_RUN_REQUEST_REJECTED("Get detect run request resulted in failure."),
122+
INVALID_NULL_FILE_IN_DEIDENTIFY_FILE("Invalid %s1 request. The file field is required and must not be null. Specify a valid file."),
123+
FILE_NOT_FOUND_TO_DEIDENTIFY("Invalid %s1 request. The file field is required and must not be empty. Specify a valid file."),
124+
FILE_NOT_READABLE_TO_DEIDENTIFY("Invalid %s1 request. The file is not readable. Please check the file permissions or path."),
125+
INVALID_PIXEL_DENSITY_TO_DEIDENTIFY_FILE("Invalid %s1 request. Pixel density must be a positive integer greater than 0. Specify a valid pixel density."),
126+
INVALID_MAX_RESOLUTION("Invalid %s1 request. Max resolution must be a positive integer greater than 0. Specify a valid max resolution."),
127+
INVALID_BLEEP_TO_DEIDENTIFY_AUDIO("Invalid %s1 request. Specify a valid bleep as AudioBleep"),
128+
OUTPUT_DIRECTORY_NOT_FOUND("Invalid %s1 request. The output directory does not exist. Please specify a valid output directory."),
129+
INVALID_PERMISSIONS_FOR_OUTPUT_DIRECTORY("Invalid %s1 request. The output directory is not writable. Please check the permissions or specify a valid output directory."),
122130
;
123131

124132
private final String log;

src/main/java/com/skyflow/utils/validations/Validations.java

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -795,62 +795,89 @@ private static void validateTokensMapWithTokenStrict(
795795

796796
public static void validateDeidentifyFileRequest(DeidentifyFileRequest request) throws SkyflowException {
797797
if (request == null) {
798-
throw new SkyflowException(ErrorMessage.EmptyRequestBody.getMessage());
798+
LogUtil.printErrorLog(Utils.parameterizedString(
799+
ErrorLogs.EMPTY_REQUEST_BODY.getLog(), InterfaceName.DETECT.getName()
800+
));
801+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyRequestBody.getMessage());
799802
}
800803

801804
File file = request.getFile();
802805
if (file == null) {
803-
throw new SkyflowException(ErrorMessage.InvalidNullFileInDeIdentifyFile.getMessage());
806+
LogUtil.printErrorLog(Utils.parameterizedString(
807+
ErrorLogs.INVALID_NULL_FILE_IN_DEIDENTIFY_FILE.getLog(), InterfaceName.DETECT.getName()
808+
));
809+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidNullFileInDeIdentifyFile.getMessage());
804810
}
805811
if (!file.exists() || !file.isFile()) {
806-
throw new SkyflowException(ErrorMessage.FileNotFoundToDeidentify.getMessage());
812+
LogUtil.printErrorLog(Utils.parameterizedString(
813+
ErrorLogs.FILE_NOT_FOUND_TO_DEIDENTIFY.getLog(), InterfaceName.DETECT.getName()
814+
));
815+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.FileNotFoundToDeidentify.getMessage());
807816
}
808817
if (!file.canRead()) {
809-
throw new SkyflowException(ErrorMessage.FileNotReadableToDeidentify.getMessage());
818+
LogUtil.printErrorLog(Utils.parameterizedString(
819+
ErrorLogs.FILE_NOT_READABLE_TO_DEIDENTIFY.getLog(), InterfaceName.DETECT.getName()
820+
));
821+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.FileNotReadableToDeidentify.getMessage());
810822
}
811823

812824

813825
// Validate pixelDensity and maxResolution
814-
if (request.getPixelDensity() != null && request.getPixelDensity() <= 0) {
815-
throw new SkyflowException(ErrorMessage.InvalidPixelDensityToDeidentifyFile.getMessage());
826+
if (request.getPixelDensity() != null && request.getPixelDensity().doubleValue() <= 0) {
827+
LogUtil.printErrorLog(Utils.parameterizedString(
828+
ErrorLogs.INVALID_PIXEL_DENSITY_TO_DEIDENTIFY_FILE.getLog(), InterfaceName.DETECT.getName()
829+
));
830+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidPixelDensityToDeidentifyFile.getMessage());
816831
}
817-
if (request.getMaxResolution() != null && request.getMaxResolution() <= 0) {
818-
throw new SkyflowException(ErrorMessage.InvalidMaxResolution.getMessage());
832+
if (request.getMaxResolution() != null && request.getMaxResolution().doubleValue() <= 0) {
833+
LogUtil.printErrorLog(Utils.parameterizedString(
834+
ErrorLogs.INVALID_MAX_RESOLUTION.getLog(), InterfaceName.DETECT.getName()
835+
));
836+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidMaxResolution.getMessage());
819837
}
820838

821839
// Validate AudioBleep
822840
if (request.getBleep() != null) {
823841
if (request.getBleep().getFrequency() == null || request.getBleep().getFrequency() <= 0) {
824-
throw new SkyflowException(ErrorMessage.InvalidRequestBody.getMessage());
842+
LogUtil.printErrorLog(Utils.parameterizedString(
843+
ErrorLogs.INVALID_BLEEP_TO_DEIDENTIFY_AUDIO.getLog(), InterfaceName.DETECT.getName()
844+
));
845+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidRequestBody.getMessage());
825846
}
826847
if (request.getBleep().getGain() == null || request.getBleep().getGain() < 0) {
827-
throw new SkyflowException(ErrorMessage.InvalidRequestBody.getMessage());
848+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidRequestBody.getMessage());
828849
}
829850
if (request.getBleep().getStartPadding() == null || request.getBleep().getStartPadding() < 0) {
830-
throw new SkyflowException(ErrorMessage.InvalidRequestBody.getMessage());
851+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidRequestBody.getMessage());
831852
}
832853
if (request.getBleep().getStopPadding() == null || request.getBleep().getStopPadding() < 0) {
833-
throw new SkyflowException(ErrorMessage.InvalidRequestBody.getMessage());
854+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidRequestBody.getMessage());
834855
}
835856
}
836857

837858
// Validate outputDirectory if provided
838859
if (request.getOutputDirectory() != null) {
839860
File outDir = new File(request.getOutputDirectory());
840861
if (!outDir.exists() || !outDir.isDirectory()) {
841-
throw new SkyflowException(ErrorMessage.OutputDirectoryNotFound.getMessage());
862+
LogUtil.printErrorLog(Utils.parameterizedString(
863+
ErrorLogs.OUTPUT_DIRECTORY_NOT_FOUND.getLog(), InterfaceName.DETECT.getName()
864+
));
865+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.OutputDirectoryNotFound.getMessage());
842866
}
843867
if (!outDir.canWrite()) {
844-
throw new SkyflowException(ErrorMessage.InvalidPermission.getMessage());
868+
LogUtil.printErrorLog(Utils.parameterizedString(
869+
ErrorLogs.INVALID_PERMISSIONS_FOR_OUTPUT_DIRECTORY.getLog(), InterfaceName.DETECT.getName()
870+
));
871+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidPermission.getMessage());
845872
}
846873
}
847874

848875
// Validate waitTime if provided
849876
if (request.getWaitTime() != null && request.getWaitTime() <= 0) {
850-
throw new SkyflowException(ErrorMessage.InvalidWaitTime.getMessage());
877+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidWaitTime.getMessage());
851878
}
852879
if(request.getWaitTime() > 64) {
853-
throw new SkyflowException(ErrorMessage.WaitTimeExceedsLimit.getMessage());
880+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.WaitTimeExceedsLimit.getMessage());
854881
}
855882
}
856883

0 commit comments

Comments
 (0)