-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fix #306: Implement approval UI extension payload * Change type of ES_OPERATION_TEMPLATE.UI to CLOB * Convert PAS OperationDetail#riskFlags to UiExtensions * Add RISK_FLAG_FRAUD_WARNING * Add test * Remove underscores from test * Replace the Czech text by English one Co-authored-by: Lubos Racansky <lubos.racansky@gmail.com>
- Loading branch information
1 parent
59ccdd2
commit 744a7cf
Showing
9 changed files
with
356 additions
and
10 deletions.
There are no files selected for viewing
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
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
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
162 changes: 162 additions & 0 deletions
162
...java/com/wultra/app/enrollmentserver/impl/service/converter/MobileTokenConverterTest.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,162 @@ | ||
/* | ||
* PowerAuth Enrollment Server | ||
* Copyright (C) 2022 Wultra s.r.o. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.wultra.app.enrollmentserver.impl.service.converter; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.wultra.app.enrollmentserver.database.entity.OperationTemplateEntity; | ||
import com.wultra.security.powerauth.client.model.enumeration.OperationStatus; | ||
import com.wultra.security.powerauth.client.model.enumeration.SignatureType; | ||
import com.wultra.security.powerauth.client.model.response.OperationDetailResponse; | ||
import com.wultra.security.powerauth.lib.mtoken.model.entity.Operation; | ||
import com.wultra.security.powerauth.lib.mtoken.model.entity.PreApprovalScreen; | ||
import com.wultra.security.powerauth.lib.mtoken.model.entity.UiExtensions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
/** | ||
* Test for {@link MobileTokenConverter}. | ||
* | ||
* @author Lubos Racansky, lubos.racansky@wultra.com | ||
*/ | ||
class MobileTokenConverterTest { | ||
|
||
private static final String TEMPLATE_UI = "{\n" + | ||
" \"flipButtons\": true,\n" + | ||
" \"blockApprovalOnCall\": false,\n" + | ||
" \"preApprovalScreen\": {\n" + | ||
" \"type\": \"WARNING\",\n" + | ||
" \"heading\": \"Watch out!\",\n" + | ||
" \"message\": \"You may become a victim of an attack.\",\n" + | ||
" \"items\": [\n" + | ||
" \"You activate a new app and allow access to your accounts\",\n" + | ||
" \"Make sure the activation takes place on your device\",\n" + | ||
" \"If you have been prompted for this operation in connection with a payment, decline it\"\n" + | ||
" ],\n" + | ||
" \"approvalType\": \"SLIDER\"\n" + | ||
" }\n" + | ||
"}"; | ||
|
||
private final MobileTokenConverter tested = new MobileTokenConverter(new ObjectMapper()); | ||
|
||
@Test | ||
void testConvertUiNull() throws Exception { | ||
final OperationDetailResponse operationDetail = new OperationDetailResponse(); | ||
operationDetail.setSignatureType(List.of(SignatureType.KNOWLEDGE)); | ||
operationDetail.setStatus(OperationStatus.APPROVED); | ||
|
||
final OperationTemplateEntity operationTemplate = new OperationTemplateEntity(); | ||
|
||
final Operation result = tested.convert(operationDetail, operationTemplate); | ||
|
||
assertNull(result.getUi()); | ||
} | ||
|
||
@Test | ||
void testConvertUiOverriddenByEnrollment() throws Exception { | ||
final OperationDetailResponse operationDetail = new OperationDetailResponse(); | ||
operationDetail.setSignatureType(List.of(SignatureType.KNOWLEDGE)); | ||
operationDetail.setStatus(OperationStatus.APPROVED); | ||
operationDetail.setRiskFlags("C"); | ||
|
||
final OperationTemplateEntity operationTemplate = new OperationTemplateEntity(); | ||
operationTemplate.setUi(TEMPLATE_UI); | ||
|
||
final Operation result = tested.convert(operationDetail, operationTemplate); | ||
|
||
assertNotNull(result.getUi()); | ||
|
||
final UiExtensions ui = result.getUi(); | ||
assertEquals(true, ui.getFlipButtons()); | ||
assertEquals(false, ui.getBlockApprovalOnCall()); | ||
assertNotNull(ui.getPreApprovalScreen()); | ||
|
||
final PreApprovalScreen preApprovalScreen = ui.getPreApprovalScreen(); | ||
assertEquals(PreApprovalScreen.ScreenType.WARNING, preApprovalScreen.getType()); | ||
assertEquals("Watch out!", preApprovalScreen.getHeading()); | ||
assertEquals("You may become a victim of an attack.", preApprovalScreen.getMessage()); | ||
assertEquals(PreApprovalScreen.ApprovalType.SLIDER, preApprovalScreen.getApprovalType()); | ||
assertNotNull(preApprovalScreen.getItems()); | ||
|
||
final List<String> items = preApprovalScreen.getItems(); | ||
assertEquals(3, items.size()); | ||
assertEquals("You activate a new app and allow access to your accounts", items.get(0)); | ||
} | ||
|
||
@Test | ||
void testConvertUiRiskFlagsX() throws Exception { | ||
final OperationDetailResponse operationDetail = new OperationDetailResponse(); | ||
operationDetail.setSignatureType(List.of(SignatureType.KNOWLEDGE)); | ||
operationDetail.setStatus(OperationStatus.APPROVED); | ||
operationDetail.setRiskFlags("X"); | ||
|
||
final OperationTemplateEntity operationTemplate = new OperationTemplateEntity(); | ||
|
||
final Operation result = tested.convert(operationDetail, operationTemplate); | ||
|
||
assertNotNull(result.getUi()); | ||
|
||
final UiExtensions ui = result.getUi(); | ||
assertEquals(true, ui.getFlipButtons()); | ||
assertNull(ui.getBlockApprovalOnCall()); | ||
assertNull(ui.getPreApprovalScreen()); | ||
} | ||
|
||
@Test | ||
void testConvertUiRiskFlagsC() throws Exception { | ||
final OperationDetailResponse operationDetail = new OperationDetailResponse(); | ||
operationDetail.setSignatureType(List.of(SignatureType.KNOWLEDGE)); | ||
operationDetail.setStatus(OperationStatus.APPROVED); | ||
operationDetail.setRiskFlags("C"); | ||
|
||
final OperationTemplateEntity operationTemplate = new OperationTemplateEntity(); | ||
|
||
final Operation result = tested.convert(operationDetail, operationTemplate); | ||
|
||
assertNotNull(result.getUi()); | ||
|
||
final UiExtensions ui = result.getUi(); | ||
assertNull(ui.getFlipButtons()); | ||
assertEquals(true, ui.getBlockApprovalOnCall()); | ||
assertNull(ui.getPreApprovalScreen()); | ||
} | ||
|
||
@Test | ||
void testConvertUiRiskFlagsXCF() throws Exception { | ||
final OperationDetailResponse operationDetail = new OperationDetailResponse(); | ||
operationDetail.setSignatureType(List.of(SignatureType.KNOWLEDGE)); | ||
operationDetail.setStatus(OperationStatus.APPROVED); | ||
operationDetail.setRiskFlags("XCF"); | ||
|
||
final OperationTemplateEntity operationTemplate = new OperationTemplateEntity(); | ||
|
||
final Operation result = tested.convert(operationDetail, operationTemplate); | ||
|
||
assertNotNull(result.getUi()); | ||
|
||
final UiExtensions ui = result.getUi(); | ||
assertEquals(true, ui.getFlipButtons()); | ||
assertEquals(true, ui.getBlockApprovalOnCall()); | ||
assertNotNull(ui.getPreApprovalScreen()); | ||
|
||
final PreApprovalScreen preApprovalScreen = ui.getPreApprovalScreen(); | ||
assertEquals(PreApprovalScreen.ScreenType.WARNING, preApprovalScreen.getType()); | ||
} | ||
} |
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
Oops, something went wrong.