11from tests .unit import AsyncHTTPTestCase
2-
2+ from flower . views . auth import authenticate , validate_auth_option
33
44class BasicAuthTests (AsyncHTTPTestCase ):
55 def test_with_single_creds (self ):
@@ -21,3 +21,41 @@ def test_with_multiple_creds(self):
2121 self .assertEqual (200 , r .code )
2222 r = self .fetch ('/' , auth_username = 'user1' , auth_password = 'pswd2' )
2323 self .assertEqual (401 , r .code )
24+
25+
26+ class AuthTests (AsyncHTTPTestCase ):
27+ def test_validate_auth_option (self ):
28+ self .assertTrue (validate_auth_option ("mail@example.com" ))
29+ self .assertTrue (validate_auth_option (".*@example.com" ))
30+ self .assertTrue (validate_auth_option ("one.*@example.com" ))
31+ self .assertTrue (validate_auth_option ("one.*two@example.com" ))
32+ self .assertFalse (validate_auth_option (".*@.*example.com" ))
33+ self .assertFalse (validate_auth_option ("one@domain1.com|.*@domain2.com" ))
34+ self .assertTrue (validate_auth_option ("one@example.com|two@example.com" ))
35+ self .assertFalse (validate_auth_option ("mail@.*example.com" ))
36+ self .assertFalse (validate_auth_option (".*example.com" ))
37+
38+ def test_authenticate_single_email (self ):
39+ self .assertTrue (authenticate ("mail@example.com" , "mail@example.com" ))
40+ self .assertFalse (authenticate ("mail@example.com" , "foo@example.com" ))
41+ self .assertFalse (authenticate ("mail@example.com" , "long.mail@example.com" ))
42+ self .assertFalse (authenticate ("mail@example.com" , "" ))
43+ self .assertFalse (authenticate ("me@gmail.com" , "me@gmail.com.attacker.com" ))
44+ self .assertFalse (authenticate ("me@gmail.com" , "*" ))
45+
46+ def test_authenticate_email_list (self ):
47+ self .assertTrue (authenticate ("one@example.com|two@example.net" , "one@example.com" ))
48+ self .assertTrue (authenticate ("one@example.com|two@example.net" , "two@example.net" ))
49+ self .assertFalse (authenticate ("one@example.com|two@example.net" , "two@example.com" ))
50+ self .assertFalse (authenticate ("one@example.com|two@example.net" , "one@example.net" ))
51+ self .assertFalse (authenticate ("one@example.com|two@example.net" , "mail@gmail.com" ))
52+ self .assertFalse (authenticate ("one@example.com|two@example.net" , "" ))
53+ self .assertFalse (authenticate ("one@example.com|two@example.net" , "*" ))
54+
55+ def test_authenticate_wildcard_email (self ):
56+ self .assertTrue (authenticate (".*@example.com" , "one@example.com" ))
57+ self .assertTrue (authenticate ("one.*@example.com" , "one@example.com" ))
58+ self .assertTrue (authenticate ("one.*@example.com" , "one.two@example.com" ))
59+ self .assertFalse (authenticate (".*@example.com" , "attacker@example.com.attacker.com" ))
60+ self .assertFalse (authenticate (".*@corp.example.com" , "attacker@corpZexample.com" ))
61+ self .assertFalse (authenticate (".*@corp\.example\.com" , "attacker@corpZexample.com" ))
0 commit comments