@@ -21,10 +21,14 @@ def test_arctic_lazy_init():
21
21
store .list_libraries ()
22
22
assert mc .called
23
23
24
- mock_conn_info = {u'authInfo' :
24
+ mock_conn_info_mongo2 = {u'authInfo' :
25
25
{u'authenticatedUsers' : [{u'user' : u'research' , u'userSource' : u'admin' }]},
26
26
u'ok' : 1.0 }
27
27
28
+ mock_conn_info_mongo3 = {u'authInfo' :
29
+ {u'authenticatedUsers' : [{u'user' : u'research' , u'db' : u'admin' }]},
30
+ u'ok' : 1.0 }
31
+
28
32
mock_conn_info_empty = {u'authInfo' :
29
33
{u'authenticatedUsers' : []},
30
34
u'ok' : 1.0 }
@@ -46,7 +50,7 @@ def test_arctic_auth():
46
50
with patch ('arctic.arctic.ArcticLibraryBinding.get_library_type' , return_value = None , autospec = True ):
47
51
ga .return_value = Credential ('db' , 'user' , 'pass' )
48
52
store ._conn ['arctic_jblackburn' ].name = 'arctic_jblackburn'
49
- store ._conn ['arctic_jblackburn' ].command .return_value = mock_conn_info
53
+ store ._conn ['arctic_jblackburn' ].command .return_value = mock_conn_info_mongo2
50
54
store ['jblackburn.library' ]
51
55
52
56
# Creating the library will have attempted to auth against it
@@ -70,7 +74,7 @@ def test_arctic_auth_custom_app_name():
70
74
with patch ('arctic.arctic.ArcticLibraryBinding.get_library_type' , return_value = None , autospec = True ):
71
75
ga .return_value = Credential ('db' , 'user' , 'pass' )
72
76
store ._conn ['arctic_jblackburn' ].name = 'arctic_jblackburn'
73
- store ._conn ['arctic_jblackburn' ].command .return_value = mock_conn_info
77
+ store ._conn ['arctic_jblackburn' ].command .return_value = mock_conn_info_mongo2
74
78
store ['jblackburn.library' ]
75
79
76
80
# Creating the library will have attempted to auth against it
@@ -102,6 +106,13 @@ def test_arctic_auth_admin_reauth():
102
106
call ('cluster' , 'arctic' , store ._adminDB .name )]
103
107
104
108
109
+ def test_arctic_is_authenticated_to ():
110
+ self = create_autospec (ArcticLibraryBinding )
111
+ assert ArcticLibraryBinding ._is_authenticated_to (self , 'admin' , mock_conn_info_mongo2 ['authInfo' ]['authenticatedUsers' ])
112
+ assert ArcticLibraryBinding ._is_authenticated_to (self , 'admin' , mock_conn_info_mongo3 ['authInfo' ]['authenticatedUsers' ])
113
+ assert not ArcticLibraryBinding ._is_authenticated_to (self , 'admin' , mock_conn_info_empty ['authInfo' ]['authenticatedUsers' ])
114
+
115
+
105
116
def test_arctic_connect_hostname ():
106
117
with patch ('pymongo.MongoClient' , return_value = MagicMock (), autospec = True ) as mc , \
107
118
patch ('arctic.arctic.mongo_retry' , autospec = True ) as ar , \
0 commit comments