2
2
# Copyright 2025 NetBox Labs, Inc.
3
3
"""Diode NetBox Plugin - Tests."""
4
4
5
+ import pytest
5
6
from django .contrib .auth import get_user_model
6
7
from django .test import TestCase
7
8
8
- from netbox_diode_plugin .plugin_config import get_diode_auth_introspect_url , get_diode_user
9
+ from netbox_diode_plugin .plugin_config import _parse_diode_target , get_diode_auth_introspect_url , get_diode_user
9
10
10
11
User = get_user_model ()
11
12
@@ -24,3 +25,46 @@ def test_get_diode_user(self):
24
25
expected_diode_user = User .objects .get (username = "diode" )
25
26
self .assertEqual (diode_user , expected_diode_user )
26
27
28
+ def test__parse_diode_target_handles_ftp_prefix (self ):
29
+ """Check that _parse_diode_target raises an error when the target contains ftp://."""
30
+ with pytest .raises (ValueError ):
31
+ _parse_diode_target ("ftp://localhost:8081" )
32
+
33
+ def test__parse_diode_target_parses_authority_correctly (self ):
34
+ """Check that _parse_diode_target parses the authority correctly."""
35
+ authority , path , tls_verify = _parse_diode_target ("grpc://localhost:8081" )
36
+ assert authority == "localhost:8081"
37
+ assert path == ""
38
+ assert tls_verify is False
39
+
40
+ def test__parse_diode_target_adds_default_port_if_missing (self ):
41
+ """Check that _parse_diode_target adds the default port if missing."""
42
+ authority , _ , _ = _parse_diode_target ("grpc://localhost" )
43
+ assert authority == "localhost:80"
44
+ authority , _ , _ = _parse_diode_target ("http://localhost" )
45
+ assert authority == "localhost:80"
46
+ authority , _ , _ = _parse_diode_target ("grpcs://localhost" )
47
+ assert authority == "localhost:443"
48
+ authority , _ , _ = _parse_diode_target ("https://localhost" )
49
+ assert authority == "localhost:443"
50
+
51
+ def test__parse_diode_target_parses_path_correctly (self ):
52
+ """Check that _parse_diode_target parses the path correctly."""
53
+ _ , path , _ = _parse_diode_target ("grpc://localhost:8081/my/path" )
54
+ assert path == "/my/path"
55
+
56
+ def test__parse_diode_target_handles_no_path (self ):
57
+ """Check that _parse_diode_target handles no path."""
58
+ _ , path , _ = _parse_diode_target ("grpc://localhost:8081" )
59
+ assert path == ""
60
+
61
+ def test__parse_diode_target_parses_tls_verify_correctly (self ):
62
+ """Check that _parse_diode_target parses tls_verify correctly."""
63
+ _ , _ , tls_verify = _parse_diode_target ("grpc://localhost:8081" )
64
+ assert tls_verify is False
65
+ _ , _ , tls_verify = _parse_diode_target ("http://localhost:8081" )
66
+ assert tls_verify is False
67
+ _ , _ , tls_verify = _parse_diode_target ("grpcs://localhost:8081" )
68
+ assert tls_verify is True
69
+ _ , _ , tls_verify = _parse_diode_target ("https://localhost:8081" )
70
+ assert tls_verify is True
0 commit comments