Debian Codegraph @

test/units/module_utils/urls/test_mask_url.py

raw
1 # -*- coding: utf-8 -*-
2 # (c) 2026 The Ansible Project
3 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4
5 from __future__ import annotations
6
7 import pytest
8
9 from ansible.module_utils.urls import mask_url
10
11
12 # for test data use 'secret' as part of any parameter that requires masking, avoid elsewhere
13 @pytest.mark.parametrize(
14 'url, wanted',
15 (
16 ('http://nothingtoseehere.com', ('nothingtoseehere.com', 'http')),
17 ('http://nothingtoseehere.com:80/stuff.asp?he=no', ('http://nothingtoseehere.com:80/stuff.asp?he=no',)),
18 ('http://nothingtoseehere.com:80?password=intheclear&user=wrongbutweignore', ('wrongbut', 'intheclear', 'password')),
19 ('https://[email protected]/index.html', ('hideme.com', 'index.html', '*')),
20 ('https://[email protected]/index.html?token=nothidden&user=alsonothidden', ('token', 'nothidden', 'alsonothidden', 'user')),
21 ('https://secretuser:[email protected]/randomfile.html', ('randomfile.html')),
22 ('https://secretuser:[email protected]:443/protected.html', ('protected.html', '443')),
23 ('ftp://secretuser:[email protected]/subdir/intheclear.txt', ('subdir', 'intheclear.txt', 'ftp', 'files.insecure')),
24 ('sftp://secretuser:[email protected]/subdir2/encrypted', ('encrypted', 'sftp')),
25 ('ftps://secretuser:[email protected]/yolo.asc', ('yolo.asc', 'file.secure')),
26 ('ftps://file.server/yolo.asc', ('yolo.asc')),
27 ('ftps://secretuser:[email protected]/yolo.asc', ('file.server/yolo.asc')),
28 ('redis://:[email protected]:6379/0', ('cache.internal', '6379', 'redis')),
29 ('amqp://:[email protected]:5672/vhost', ('rabbit.internal', '5672', 'vhost')),
30 )
31 )
32 def test_mask_url(url, wanted):
33
34 masked = mask_url(url)
35 assert 'secret' not in masked
36
37 for notmasked in wanted:
38 assert notmasked in masked