-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
125 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ Content-Type: application/json | |
Authorization: Bearer {{auth_token}} | ||
|
||
{ | ||
"email": "user1@email.com", | ||
"email": "user2@email.com", | ||
"password": "secret!", | ||
"firstName": "Admin", | ||
"lastName": "", | ||
|
@@ -43,7 +43,7 @@ Content-Type: application/json | |
Authorization: Bearer {{auth_token}} | ||
|
||
{ | ||
"email": "admin2@email.com" | ||
"email": "user2@email.com" | ||
} | ||
|
||
|
||
|
@@ -72,21 +72,21 @@ Authorization: Bearer {{auth_token}} | |
|
||
POST {{host}}/api/mfa/enrollment | ||
Content-Type: application/json | ||
Authorization: Bearer eyJraWQiOiJkYTFiNzAwMS05NjlkLTQyNzQtYTM5Yy0wYTI2ZjMzODg2NmIiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJhZG1pbkBlbWFpbC5jb20iLCJhdWQiOiJ1c2VyLWludHJvc3BlY3Rpb24iLCJuYmYiOjE3MjE4OTM1NDIsInVzZXJfbmFtZSI6ImFkbWluQGVtYWlsLmNvbSIsInNjb3BlIjpbIm9wZW5pZCIsImVtYWlsIiwicHJvZmlsZSJdLCJpc3MiOiJodHRwOi8vbG9jYWwuYXBpLnZhdXRoZW50aWNhdG9yLmNvbTo5MDkwIiwiZXhwIjoxNzIxODkzOTAyLCJpYXQiOjE3MjE4OTM1NDIsImp0aSI6ImU2ZDYyMWQzLTJjZmUtNDE1ZC04NGM4LTE0NjEwNGNiZTM2NiIs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gUHE_IxSjX7isWjfWI0lJDK7S7wfKtU4Q_-5dCQq6l26IpOHhE_LXwhVFoBlnGxh_VhGg1fVesVgDX9he-QQxB0LKKJkL9UIKd0BPjgLUZGTSxHhLInhU7wumbPO2Z9TB5bDayOr77ilo5eAPma8c8zUem_BGhcGi3JuiPMfUuqmjPMyYGy_E1XmblQ | ||
|
||
{ | ||
"mfaMethod": "EMAIL_MFA_METHOD", | ||
"mfaChannel" : "admin11@email.com" | ||
"mfaChannel" : "user2_123@email.com" | ||
} | ||
|
||
|
||
### associate new email | ||
|
||
POST {{host}}/api/mfa/associate?ticket= | ||
POST {{host}}/api/mfa/associate | ||
Content-Type: application/json | ||
Authorization: Bearer eyJraWQiOiJkYTFiNzAwMS05NjlkLTQyNzQtYTM5Yy0wYTI2ZjMzODg2NmIiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJhZG1pbkBlbWFpbC5jb20iLCJhdWQiOiJ1c2VyLWludHJvc3BlY3Rpb24iLCJuYmYiOjE3MjE4OTM1NDIsInVzZXJfbmFtZSI6ImFkbWluQGVtYWlsLmNvbSIsInNjb3BlIjpbIm9wZW5pZCIsImVtYWlsIiwicHJvZmlsZSJdLCJpc3MiOiJodHRwOi8vbG9jYWwuYXBpLnZhdXRoZW50aWNhdG9yLmNvbTo5MDkwIiwiZXhwIjoxNzIxODkzOTAyLCJpYXQiOjE3MjE4OTM1NDIsImp0aSI6ImU2ZDYyMWQzLTJjZmUtNDE1ZC04NGM4LTE0NjEwNGNiZTM2NiIsImF1dGhvcml0aWVzIjpbIlJPTEVfVVNFUiIsIlZBVVRIRU5USUNBVE9SX0FETUlOIl19.zwd43a7ZZvBizh4ebW6r36aQRmhSj8oHt21HRScGU2mHn0mOR1OEHMhw-0QPRwW75XfcwhpnLk05k9C2VDd-Nx4d_GZn13qgmnTFK-BPBxm620hbWR3arW8sXYSMzDZTZDGQRPDCUBqJigDS51hVZfyA5LvoFdzfbOQsyKXvd-ZDgjfBNFJSt20V9GlS11g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ticket": "cd6c4b8c-e136-4fec-ad2d-c1bda930dc9e", | ||
"code" : "505509" | ||
} |
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
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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package com.vauthenticator.server.mfa.domain | ||
|
||
import com.vauthenticator.server.clientapp.ClientAppFixture.aClientAppId | ||
import com.vauthenticator.server.keys.Kid | ||
import com.vauthenticator.server.mfa.domain.MfaMethod.EMAIL_MFA_METHOD | ||
import com.vauthenticator.server.mfa.repository.MfaAccountMethodsRepository | ||
import com.vauthenticator.server.support.AccountTestFixture.anAccount | ||
import com.vauthenticator.server.support.TicketFixture.ticketContext | ||
|
@@ -16,6 +18,9 @@ import junit.framework.TestCase.assertEquals | |
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import java.util.* | ||
|
||
private const val emailMfaChannel = "[email protected]" | ||
|
||
@ExtendWith(MockKExtension::class) | ||
class MfaMethodsEnrollmentTest { | ||
|
@@ -31,6 +36,16 @@ class MfaMethodsEnrollmentTest { | |
|
||
private lateinit var uut: MfaMethodsEnrollment | ||
|
||
private val account = anAccount() | ||
private val clientAppId = aClientAppId() | ||
private val ticketId = TicketId("A_TICKET") | ||
private val emailMfaAccountMethod = MfaAccountMethod( | ||
account.email, | ||
Kid("A_KID"), | ||
EMAIL_MFA_METHOD, | ||
emailMfaChannel | ||
) | ||
|
||
@BeforeEach | ||
fun setUp() { | ||
uut = MfaMethodsEnrollment( | ||
|
@@ -42,38 +57,52 @@ class MfaMethodsEnrollmentTest { | |
|
||
@Test | ||
fun `when the enrolment do not send the verification code together the verification ticket`() { | ||
val account = anAccount() | ||
val clientAppId = aClientAppId() | ||
|
||
every { | ||
mfaAccountMethodsRepository.findOne( | ||
account.email, | ||
EMAIL_MFA_METHOD, | ||
emailMfaChannel | ||
) | ||
} returns Optional.of(emailMfaAccountMethod) | ||
every { ticketCreator.createTicketFor(account, clientAppId, ticketContext(emailMfaChannel)) } returns ticketId | ||
|
||
val ticketId = TicketId("A_TICKET") | ||
val actual = uut.enroll(account, EMAIL_MFA_METHOD, emailMfaChannel, clientAppId, false) | ||
|
||
every { ticketCreator.createTicketFor(account, clientAppId, ticketContext(account.email)) } returns ticketId | ||
val actual = uut.enroll(account, MfaMethod.EMAIL_MFA_METHOD, account.email, clientAppId, false) | ||
verify { | ||
ticketCreator.createTicketFor( | ||
account, clientAppId, ticketContext(account.email) | ||
mfaAccountMethodsRepository.findOne( | ||
account.email, | ||
EMAIL_MFA_METHOD, | ||
emailMfaChannel | ||
) | ||
} | ||
verify { ticketCreator.createTicketFor(account, clientAppId, ticketContext(emailMfaChannel)) } | ||
|
||
assertEquals(ticketId, actual) | ||
} | ||
|
||
@Test | ||
fun `when the enrolment send the verification code together the verification ticket`() { | ||
val account = anAccount() | ||
val clientAppId = aClientAppId() | ||
|
||
|
||
val ticketId = TicketId("A_TICKET") | ||
|
||
every { ticketCreator.createTicketFor(account, clientAppId, ticketContext(account.email)) } returns ticketId | ||
every { mfaSender.sendMfaChallenge(account.email, account.email) } just runs | ||
every { | ||
mfaAccountMethodsRepository.findOne( | ||
account.email, | ||
EMAIL_MFA_METHOD, | ||
emailMfaChannel | ||
) | ||
} returns Optional.of(emailMfaAccountMethod) | ||
every { ticketCreator.createTicketFor(account, clientAppId, ticketContext(emailMfaChannel)) } returns ticketId | ||
every { mfaSender.sendMfaChallenge(account.email, emailMfaChannel) } just runs | ||
|
||
val actual = uut.enroll(account, MfaMethod.EMAIL_MFA_METHOD, account.email, clientAppId, true) | ||
val actual = uut.enroll(account, EMAIL_MFA_METHOD, emailMfaChannel, clientAppId, true) | ||
|
||
verify { ticketCreator.createTicketFor(account, clientAppId, ticketContext(account.email)) } | ||
verify { mfaSender.sendMfaChallenge(account.email, account.email) } | ||
verify { | ||
mfaAccountMethodsRepository.findOne( | ||
account.email, | ||
EMAIL_MFA_METHOD, | ||
emailMfaChannel | ||
) | ||
} | ||
verify { ticketCreator.createTicketFor(account, clientAppId, ticketContext(emailMfaChannel)) } | ||
verify { mfaSender.sendMfaChallenge(account.email, emailMfaChannel) } | ||
|
||
assertEquals(ticketId, actual) | ||
} | ||
|
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.