Skip to content

Commit 11d5daa

Browse files
authored
fix(auth): Removed MultiFactoryID public type (#431)
1 parent ef8f341 commit 11d5daa

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

auth/user_mgt.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,12 @@ type multiFactorInfoResponse struct {
6565
EnrolledAt string `json:"enrolledAt,omitempty"`
6666
}
6767

68-
// MultiFactorID represents the type of an enrolled factor, for now only Phone
69-
// is available.
70-
type MultiFactorID string
71-
72-
const (
73-
// Phone represents an enrolled factor of type Phone / SMS
74-
Phone MultiFactorID = "phone"
75-
)
76-
7768
// MultiFactorInfo describes a user enrolled second phone factor.
7869
type MultiFactorInfo struct {
7970
UID string
8071
DisplayName string
8172
EnrollmentTimestamp int64
82-
FactorID MultiFactorID
73+
FactorID string
8374
PhoneNumber string
8475
}
8576

@@ -994,11 +985,15 @@ func (r *userQueryResponse) makeExportedUserRecord() (*ExportedUserRecord, error
994985
enrollmentTimestamp = t.Unix() * 1000
995986
}
996987

988+
if factor.PhoneInfo == "" {
989+
return nil, fmt.Errorf("unsupported multi-factor auth response: %#v", factor)
990+
}
991+
997992
enrolledFactors = append(enrolledFactors, &MultiFactorInfo{
998993
UID: factor.MFAEnrollmentID,
999994
DisplayName: factor.DisplayName,
1000995
EnrollmentTimestamp: enrollmentTimestamp,
1001-
FactorID: Phone,
996+
FactorID: "phone",
1002997
PhoneNumber: factor.PhoneInfo,
1003998
})
1004999
}

auth/user_mgt_test.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ var testUser = &UserRecord{
4444
PhotoURL: "http://www.example.com/testuser/photo.png",
4545
ProviderID: defaultProviderID,
4646
},
47-
Disabled: false,
48-
47+
Disabled: false,
4948
EmailVerified: true,
5049
ProviderUserInfo: []*UserInfo{
5150
{
@@ -71,7 +70,7 @@ var testUser = &UserRecord{
7170
EnrolledFactors: []*MultiFactorInfo{
7271
{
7372
UID: "0aaded3f-5e73-461d-aef9-37b48e3769be",
74-
FactorID: Phone,
73+
FactorID: "phone",
7574
EnrollmentTimestamp: 1614776780000,
7675
PhoneNumber: "+1234567890",
7776
DisplayName: "My MFA Phone",
@@ -80,7 +79,6 @@ var testUser = &UserRecord{
8079
},
8180
}
8281

83-
var emptyFactors []*MultiFactorInfo
8482
var testUserWithoutMFA = &UserRecord{
8583
UserInfo: &UserInfo{
8684
UID: "testusernomfa",
@@ -90,8 +88,7 @@ var testUserWithoutMFA = &UserRecord{
9088
PhotoURL: "http://www.example.com/testusernomfa/photo.png",
9189
ProviderID: defaultProviderID,
9290
},
93-
Disabled: false,
94-
91+
Disabled: false,
9592
EmailVerified: true,
9693
ProviderUserInfo: []*UserInfo{
9794
{
@@ -113,9 +110,7 @@ var testUserWithoutMFA = &UserRecord{
113110
},
114111
CustomClaims: map[string]interface{}{"admin": true, "package": "gold"},
115112
TenantID: "testTenant",
116-
MultiFactor: &MultiFactorSettings{
117-
EnrolledFactors: emptyFactors,
118-
},
113+
MultiFactor: &MultiFactorSettings{},
119114
}
120115

121116
func TestGetUser(t *testing.T) {
@@ -1677,6 +1672,22 @@ func TestMakeExportedUser(t *testing.T) {
16771672
}
16781673
}
16791674

1675+
func TestUnsupportedAuthFactor(t *testing.T) {
1676+
queryResponse := &userQueryResponse{
1677+
UID: "uid1",
1678+
MFAInfo: []*multiFactorInfoResponse{
1679+
{
1680+
MFAEnrollmentID: "enrollementId",
1681+
},
1682+
},
1683+
}
1684+
1685+
exported, err := queryResponse.makeExportedUserRecord()
1686+
if exported != nil || err == nil {
1687+
t.Errorf("makeExportedUserRecord() = (%v, %v); want = (nil, error)", exported, err)
1688+
}
1689+
}
1690+
16801691
func TestExportedUserRecordShouldClearRedacted(t *testing.T) {
16811692
queryResponse := &userQueryResponse{
16821693
UID: "uid1",

0 commit comments

Comments
 (0)