@@ -125,11 +125,76 @@ func TestAzureProviderGetEmailAddress(t *testing.T) {
125125 b := testAzureBackend(`{ "mail": "user@windows.net" }`)
126126 defer b.Close()
127127
128− b_url, _ := url.Parse(b.URL)
129− p := testAzureProvider(b_url.Host)
128+ bURL, _ := url.Parse(b.URL)
129+ p := testAzureProvider(bURL.Host)
130130
131131 session := &SessionState{AccessToken: "imaginary_access_token"}
132132 email, err := p.GetEmailAddress(session)
133133 assert.Equal(t, nil, err)
134134 assert.Equal(t, "user@windows.net", email)
135135}
136+
137+func TestAzureProviderGetEmailAddressMailNull(t *testing.T) {
138+ b := testAzureBackend(`{ "mail": null, "otherMails": ["user@windows.net", "altuser@windows.net"] }`)
139+ defer b.Close()
140+
141+ bURL, _ := url.Parse(b.URL)
142+ p := testAzureProvider(bURL.Host)
143+
144+ session := &SessionState{AccessToken: "imaginary_access_token"}
145+ email, err := p.GetEmailAddress(session)
146+ assert.Equal(t, nil, err)
147+ assert.Equal(t, "user@windows.net", email)
148+}
149+
150+func TestAzureProviderGetEmailAddressGetUserPrincipalName(t *testing.T) {
151+ b := testAzureBackend(`{ "mail": null, "otherMails": [], "userPrincipalName": "user@windows.net" }`)
152+ defer b.Close()
153+
154+ bURL, _ := url.Parse(b.URL)
155+ p := testAzureProvider(bURL.Host)
156+
157+ session := &SessionState{AccessToken: "imaginary_access_token"}
158+ email, err := p.GetEmailAddress(session)
159+ assert.Equal(t, nil, err)
160+ assert.Equal(t, "user@windows.net", email)
161+}
162+
163+func TestAzureProviderGetEmailAddressFailToGetEmailAddress(t *testing.T) {
164+ b := testAzureBackend(`{ "mail": null, "otherMails": [], "userPrincipalName": null }`)
165+ defer b.Close()
166+
167+ bURL, _ := url.Parse(b.URL)
168+ p := testAzureProvider(bURL.Host)
169+
170+ session := &SessionState{AccessToken: "imaginary_access_token"}
171+ email, err := p.GetEmailAddress(session)
172+ assert.Equal(t, "type assertion to string failed", err.Error())
173+ assert.Equal(t, "", email)
174+}
175+
176+func TestAzureProviderGetEmailAddressEmptyUserPrincipalName(t *testing.T) {
177+ b := testAzureBackend(`{ "mail": null, "otherMails": [], "userPrincipalName": "" }`)
178+ defer b.Close()
179+
180+ bURL, _ := url.Parse(b.URL)
181+ p := testAzureProvider(bURL.Host)
182+
183+ session := &SessionState{AccessToken: "imaginary_access_token"}
184+ email, err := p.GetEmailAddress(session)
185+ assert.Equal(t, nil, err)
186+ assert.Equal(t, "", email)
187+}
188+
189+func TestAzureProviderGetEmailAddressIncorrectOtherMails(t *testing.T) {
190+ b := testAzureBackend(`{ "mail": null, "otherMails": "", "userPrincipalName": null }`)
191+ defer b.Close()
192+
193+ bURL, _ := url.Parse(b.URL)
194+ p := testAzureProvider(bURL.Host)
195+
196+ session := &SessionState{AccessToken: "imaginary_access_token"}
197+ email, err := p.GetEmailAddress(session)
198+ assert.Equal(t, "type assertion to string failed", err.Error())
199+ assert.Equal(t, "", email)
200+}