@@ -252,3 +252,93 @@ def test_cleanup_users(admin: VaultwardenAdminClient):
252252 for i in admin .users ():
253253 if i .Email .endswith ("@example.org" ):
254254 admin .delete (i .Id )
255+
256+
257+ SEARCH_ITEMS = [
258+ # ("http://default.com", "http://default.com", None),
259+ (
260+ "http://sub.basedomain.com" ,
261+ "http://basedomain.com" ,
262+ UriMatchDetection .BASEDOMAIN ,
263+ ),
264+ ("http://host.com/a" , "http://host.com" , UriMatchDetection .HOST ),
265+ (
266+ "http://startswith.com/a/b" ,
267+ "http://startswith.com/a" ,
268+ UriMatchDetection .STARTSWITH ,
269+ ),
270+ ("http://re.com" , r"^http://re\.c.m" , UriMatchDetection .RE ),
271+ ("http://exact.com" , "http://exact.com" , UriMatchDetection .EXACT ),
272+ ]
273+
274+
275+ @pytest .fixture (
276+ params = SEARCH_ITEMS ,
277+ ids = [urllib .parse .urlparse (url ).hostname for url , * _ in SEARCH_ITEMS ],
278+ )
279+ def logins (request , test_account , organization , collection ):
280+ url , uri , match = request .param
281+ name = urllib .parse .urlparse (url ).hostname
282+ data = LoginData .model_construct (
283+ name = name ,
284+ password = "test123" ,
285+ username = "test" ,
286+ Uris = [UriMatch .model_construct (match = match , uri = uri )],
287+ )
288+ item = Login .model_construct (
289+ name = name ,
290+ login = data ,
291+ data = data ,
292+ key = secrets .token_bytes (64 ),
293+ )
294+ test_account .create_item (item , organization , [collection ])
295+ return url , uri , match
296+
297+
298+ def test_search (
299+ test_account : BitwardenAPIClient ,
300+ organization : Organization ,
301+ collection : OrganizationCollection ,
302+ logins ,
303+ ):
304+ test_account .sync (force_refresh = True )
305+ url , uri , match = logins
306+
307+ r = list (
308+ test_account .search_items (
309+ url , organisations = [organization ], collections = [collection ]
310+ )
311+ )
312+ assert len (r ) == 1 , url
313+ assert r [0 ].Name == urllib .parse .urlparse (url ).hostname
314+
315+
316+ def test_edit (
317+ test_account : BitwardenAPIClient ,
318+ organization : Organization ,
319+ collection : OrganizationCollection ,
320+ logins ,
321+ ):
322+ test_account .sync (force_refresh = True )
323+ url , uri , match = logins
324+
325+ r = list (
326+ test_account .search_items (
327+ url , organisations = [organization ], collections = [collection ]
328+ )
329+ )
330+ assert len (r ) == 1 , url
331+ assert r [0 ].Name == urllib .parse .urlparse (url ).hostname
332+ lo : Login = r [0 ]
333+ assert lo .Login .username == "test"
334+ lo .Login .username = lo .Login .password = "edit"
335+ lo .save ()
336+ test_account .sync (force_refresh = True )
337+ r = list (
338+ test_account .search_items (
339+ url , organisations = [organization ], collections = [collection ]
340+ )
341+ )
342+ assert len (r ) == 1 , url
343+ lo : Login = r [0 ]
344+ assert lo .Login .username == lo .Login .password == "edit"
0 commit comments