-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(auth): Add TotpInfo
field to UserRecord
#558
Changes from 19 commits
54b8114
cef91ac
77177c7
a957589
eb0d2a0
05378ef
4121c50
928b104
02cde4f
6b40682
e60757f
bb055ed
23a1f17
1d24577
61c6c04
3f140e0
e178eb3
8c41cc7
4c5e08f
d29e057
6921afb
ce0bac0
79321fe
b756b71
939d6c0
09d8eaa
f448782
336ca6d
587f0df
34b2f98
3535bbd
e13f10c
b1a5ac8
7495d4f
b4a93cf
afce475
afdd057
b9aa6d6
939a446
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,11 +69,20 @@ var testUser = &UserRecord{ | |
MultiFactor: &MultiFactorSettings{ | ||
EnrolledFactors: []*MultiFactorInfo{ | ||
{ | ||
UID: "0aaded3f-5e73-461d-aef9-37b48e3769be", | ||
UID: "enrolledPhoneFactor", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: can we keep the previous UID which is more representative of what the UID looks like? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer it this way since we can test UIDs with integration tests but for more clarity as we add unit tests this might be better. What do you think? We can revert back to the previous UID and add comments if you feel strongly about this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I am not sure what the human-readable UID gives us that the other alphanumeric value does not. Can you elaborate? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like you said, human-readable. It is just easier to write unit test cases as we add more factors here. I guess it doesn't make a lot of difference to have alphanumeric strings for unit tests as such because these are generated by the backend in the actual flow. |
||
FactorID: "phone", | ||
EnrollmentTimestamp: 1614776780000, | ||
PhoneNumber: "+1234567890", | ||
DisplayName: "My MFA Phone", | ||
PhoneMultiFactorInfo: &PhoneMultiFactorInfo{ | ||
PhoneNumber: "+1234567890", | ||
}, | ||
DisplayName: "My MFA Phone", | ||
}, | ||
{ | ||
UID: "enrolledTOTPFactor", | ||
FactorID: "totp", | ||
EnrollmentTimestamp: 1614776780000, | ||
TOTPMultiFactorInfo: &TOTPMultiFactorInfo{}, | ||
DisplayName: "My MFA TOTP", | ||
}, | ||
}, | ||
}, | ||
|
@@ -646,8 +655,10 @@ func TestInvalidCreateUser(t *testing.T) { | |
(&UserToCreate{}).MFASettings(MultiFactorSettings{ | ||
EnrolledFactors: []*MultiFactorInfo{ | ||
{ | ||
UID: "EnrollmentID", | ||
PhoneNumber: "+11234567890", | ||
UID: "EnrollmentID", | ||
PhoneMultiFactorInfo: &PhoneMultiFactorInfo{ | ||
PhoneNumber: "+11234567890", | ||
}, | ||
DisplayName: "Spouse's phone number", | ||
FactorID: "phone", | ||
}, | ||
|
@@ -658,7 +669,9 @@ func TestInvalidCreateUser(t *testing.T) { | |
(&UserToCreate{}).MFASettings(MultiFactorSettings{ | ||
EnrolledFactors: []*MultiFactorInfo{ | ||
{ | ||
PhoneNumber: "invalid", | ||
PhoneMultiFactorInfo: &PhoneMultiFactorInfo{ | ||
PhoneNumber: "invalid", | ||
}, | ||
DisplayName: "Spouse's phone number", | ||
FactorID: "phone", | ||
}, | ||
|
@@ -669,7 +682,9 @@ func TestInvalidCreateUser(t *testing.T) { | |
(&UserToCreate{}).MFASettings(MultiFactorSettings{ | ||
EnrolledFactors: []*MultiFactorInfo{ | ||
{ | ||
PhoneNumber: "+11234567890", | ||
PhoneMultiFactorInfo: &PhoneMultiFactorInfo{ | ||
PhoneNumber: "+11234567890", | ||
}, | ||
DisplayName: "Spouse's phone number", | ||
FactorID: "phone", | ||
EnrollmentTimestamp: time.Now().UTC().Unix(), | ||
|
@@ -681,7 +696,9 @@ func TestInvalidCreateUser(t *testing.T) { | |
(&UserToCreate{}).MFASettings(MultiFactorSettings{ | ||
EnrolledFactors: []*MultiFactorInfo{ | ||
{ | ||
PhoneNumber: "+11234567890", | ||
PhoneMultiFactorInfo: &PhoneMultiFactorInfo{ | ||
PhoneNumber: "+11234567890", | ||
}, | ||
DisplayName: "Spouse's phone number", | ||
FactorID: "", | ||
}, | ||
|
@@ -692,8 +709,10 @@ func TestInvalidCreateUser(t *testing.T) { | |
(&UserToCreate{}).MFASettings(MultiFactorSettings{ | ||
EnrolledFactors: []*MultiFactorInfo{ | ||
{ | ||
PhoneNumber: "+11234567890", | ||
FactorID: "phone", | ||
PhoneMultiFactorInfo: &PhoneMultiFactorInfo{ | ||
PhoneNumber: "+11234567890", | ||
}, | ||
FactorID: "phone", | ||
}, | ||
}, | ||
}), | ||
|
@@ -773,7 +792,9 @@ var createUserCases = []struct { | |
(&UserToCreate{}).MFASettings(MultiFactorSettings{ | ||
EnrolledFactors: []*MultiFactorInfo{ | ||
{ | ||
PhoneNumber: "+11234567890", | ||
PhoneMultiFactorInfo: &PhoneMultiFactorInfo{ | ||
PhoneNumber: "+11234567890", | ||
}, | ||
DisplayName: "Spouse's phone number", | ||
FactorID: "phone", | ||
}, | ||
|
@@ -790,12 +811,16 @@ var createUserCases = []struct { | |
(&UserToCreate{}).MFASettings(MultiFactorSettings{ | ||
EnrolledFactors: []*MultiFactorInfo{ | ||
{ | ||
PhoneNumber: "+11234567890", | ||
PhoneMultiFactorInfo: &PhoneMultiFactorInfo{ | ||
PhoneNumber: "+11234567890", | ||
}, | ||
DisplayName: "number1", | ||
FactorID: "phone", | ||
}, | ||
{ | ||
PhoneNumber: "+11234567890", | ||
PhoneMultiFactorInfo: &PhoneMultiFactorInfo{ | ||
PhoneNumber: "+11234567890", | ||
}, | ||
DisplayName: "number2", | ||
FactorID: "phone", | ||
}, | ||
|
@@ -875,9 +900,11 @@ func TestInvalidUpdateUser(t *testing.T) { | |
(&UserToUpdate{}).MFASettings(MultiFactorSettings{ | ||
EnrolledFactors: []*MultiFactorInfo{ | ||
{ | ||
UID: "enrolledSecondFactor1", | ||
PhoneNumber: "+11234567890", | ||
FactorID: "phone", | ||
UID: "enrolledSecondFactor1", | ||
PhoneMultiFactorInfo: &PhoneMultiFactorInfo{ | ||
PhoneNumber: "+11234567890", | ||
}, | ||
FactorID: "phone", | ||
}, | ||
}, | ||
}), | ||
|
@@ -886,25 +913,16 @@ func TestInvalidUpdateUser(t *testing.T) { | |
(&UserToUpdate{}).MFASettings(MultiFactorSettings{ | ||
EnrolledFactors: []*MultiFactorInfo{ | ||
{ | ||
UID: "enrolledSecondFactor1", | ||
PhoneNumber: "invalid", | ||
UID: "enrolledSecondFactor1", | ||
PhoneMultiFactorInfo: &PhoneMultiFactorInfo{ | ||
PhoneNumber: "invalid", | ||
}, | ||
DisplayName: "Spouse's phone number", | ||
FactorID: "phone", | ||
}, | ||
}, | ||
}), | ||
`the second factor "phoneNumber" for "invalid" must be a non-empty E.164 standard compliant identifier string`, | ||
}, { | ||
(&UserToUpdate{}).MFASettings(MultiFactorSettings{ | ||
EnrolledFactors: []*MultiFactorInfo{ | ||
{ | ||
PhoneNumber: "+11234567890", | ||
FactorID: "phone", | ||
DisplayName: "Spouse's phone number", | ||
}, | ||
}, | ||
}), | ||
`the second factor "uid" must be a valid non-empty string when adding second factors via "updateUser()"`, | ||
}, { | ||
(&UserToUpdate{}).ProviderToLink(&UserProvider{UID: "google_uid"}), | ||
"user provider must specify a provider ID", | ||
|
@@ -1049,20 +1067,30 @@ var updateUserCases = []struct { | |
(&UserToUpdate{}).MFASettings(MultiFactorSettings{ | ||
EnrolledFactors: []*MultiFactorInfo{ | ||
{ | ||
UID: "enrolledSecondFactor1", | ||
PhoneNumber: "+11234567890", | ||
UID: "enrolledSecondFactor1", | ||
PhoneMultiFactorInfo: &PhoneMultiFactorInfo{ | ||
PhoneNumber: "+11234567890", | ||
}, | ||
DisplayName: "Spouse's phone number", | ||
FactorID: "phone", | ||
EnrollmentTimestamp: time.Now().Unix(), | ||
}, { | ||
UID: "enrolledSecondFactor2", | ||
PhoneNumber: "+11234567890", | ||
UID: "enrolledSecondFactor2", | ||
PhoneMultiFactorInfo: &PhoneMultiFactorInfo{ | ||
PhoneNumber: "+11234567890", | ||
}, | ||
DisplayName: "Spouse's phone number", | ||
FactorID: "phone", | ||
}, { | ||
PhoneMultiFactorInfo: &PhoneMultiFactorInfo{ | ||
PhoneNumber: "+11234567890", | ||
}, | ||
DisplayName: "Spouse's phone number", | ||
FactorID: "phone", | ||
}, | ||
}, | ||
}), | ||
map[string]interface{}{"mfaInfo": []*multiFactorInfoResponse{ | ||
map[string]interface{}{"mfa": multiFactorEnrollments{Enrollments: []*multiFactorInfoResponse{ | ||
{ | ||
MFAEnrollmentID: "enrolledSecondFactor1", | ||
PhoneInfo: "+11234567890", | ||
|
@@ -1074,12 +1102,16 @@ var updateUserCases = []struct { | |
DisplayName: "Spouse's phone number", | ||
PhoneInfo: "+11234567890", | ||
}, | ||
}, | ||
{ | ||
DisplayName: "Spouse's phone number", | ||
PhoneInfo: "+11234567890", | ||
}, | ||
}}, | ||
}, | ||
}, | ||
{ | ||
(&UserToUpdate{}).MFASettings(MultiFactorSettings{}), | ||
map[string]interface{}{"mfaInfo": nil}, | ||
map[string]interface{}{"mfa": multiFactorEnrollments{Enrollments: nil}}, | ||
}, | ||
{ | ||
(&UserToUpdate{}).ProviderToLink(&UserProvider{ | ||
|
@@ -1886,10 +1918,16 @@ func TestMakeExportedUser(t *testing.T) { | |
MFAInfo: []*multiFactorInfoResponse{ | ||
{ | ||
PhoneInfo: "+1234567890", | ||
MFAEnrollmentID: "0aaded3f-5e73-461d-aef9-37b48e3769be", | ||
MFAEnrollmentID: "enrolledPhoneFactor", | ||
DisplayName: "My MFA Phone", | ||
EnrolledAt: "2021-03-03T13:06:20.542896Z", | ||
}, | ||
{ | ||
TOTPInfo: &TOTPInfo{}, | ||
MFAEnrollmentID: "enrolledTOTPFactor", | ||
DisplayName: "My MFA TOTP", | ||
EnrolledAt: "2021-03-03T13:06:20.542896Z", | ||
}, | ||
}, | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a user-facing field? If yes, we need an API review for it, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we cannot merge this until the API change is approved, right? Can we keep PhoneNumber for now and merge the rest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working on the API proposal for this.