コード例 #1
0
def test_of_empty_trust_domain():
    with pytest.raises(ArgumentError) as exception:
        SpiffeId.of('', 'path')

    assert (
        str(exception.value)
        == 'SPIFFE ID: trust_domain argument must be a TrustDomain instance.'
    )
コード例 #2
0
def test_of_with_all_chars():
    # Go all the way through 255, which ensures we reject UTF-8 appropriately
    for i in range(0, 255):
        c = chr(i)

        # Don't test '/' since it is the delimiter between path segments
        if c == '/':
            continue

        path1 = '/Path1' + c
        path2 = '/Path2' + c
        trust_domain = TrustDomain.parse('trustdomain')

        if c in PATH_CHARS:
            spiffe_id = SpiffeId.of(trust_domain, [path1, path2])
            assert str(spiffe_id) == 'spiffe://trustdomain' + path1 + path2
        else:
            with pytest.raises(SpiffeIdError) as exception:
                SpiffeId.of('spiffe://trustdomain', [path1, path2])
            assert (
                str(exception.value) ==
                'Path segment characters are limited to letters, numbers, dots, dashes, and underscores.'
            )
コード例 #3
0
def test_of_empty_trust_domain():
    with pytest.raises(ArgumentError) as exception:
        SpiffeId.of('', '/path')

    assert str(exception.value) == 'Trust domain is missing.'
コード例 #4
0
def test_trust_domain_none():
    with pytest.raises(ArgumentError) as exception:
        SpiffeId.of(None, '/path')

    assert str(exception.value) == 'Trust domain is missing.'
コード例 #5
0
def test_not_equal_spiffe_ids():
    trust_domain = TrustDomain.parse('trustdomain')
    spiffeid_1 = SpiffeId.of(trust_domain, '/path1')
    spiffeid_2 = SpiffeId.of(trust_domain, '/path2')
    assert spiffeid_1 != spiffeid_2
コード例 #6
0
def test_equal_spiffe_id_with_multiple_paths():
    trust_domain = TrustDomain.parse('trustdomain')
    spiffeid_1 = SpiffeId.of(trust_domain, ['/PATH1', '/PATH2'])
    spiffeid_2 = SpiffeId.of(trust_domain, ['/PATH1', '/PATH2'])
    assert spiffeid_1 == spiffeid_2
コード例 #7
0
def test_of_trust_domain_and_invalid_segments(trust_domain, path_segments,
                                              expected_error):
    with pytest.raises(SpiffeIdError) as exception:
        SpiffeId.of(trust_domain, path_segments)
    assert str(exception.value) == expected_error
コード例 #8
0
def test_of_trust_domain_and_segments(trust_domain, path_segments,
                                      expected_spiffe_id):
    result = SpiffeId.of(trust_domain, path_segments)
    assert str(result) == expected_spiffe_id
コード例 #9
0
def test_trust_domain_none():
    with pytest.raises(ArgumentError) as exception:
        SpiffeId.of(None, 'path')

    assert str(exception.value) == 'SPIFFE ID: trust domain cannot be empty.'
コード例 #10
0
def test_not_equal_when_different_objects():
    trust_domain = TrustDomain('domain.test')
    spiffeid_1 = SpiffeId.of(trust_domain, 'path1')
    assert spiffeid_1 != trust_domain
コード例 #11
0
def test_not_equal_spiffe_ids():
    trust_domain = TrustDomain('domain.test')
    spiffeid_1 = SpiffeId.of(trust_domain, 'path1')
    spiffeid_2 = SpiffeId.of(trust_domain, 'path2')
    assert spiffeid_1 != spiffeid_2
コード例 #12
0
def test_equal_spiffe_id_with_multiple_paths():
    trust_domain = TrustDomain('example.org')
    spiffeid_1 = SpiffeId.of(trust_domain, ['PATH1', 'PATH2'])
    spiffeid_2 = SpiffeId.of(trust_domain, ['/PATH1', '/PATH2'])
    assert spiffeid_1 == spiffeid_2
コード例 #13
0
def test_equal_spiffe_id():
    trust_domain = TrustDomain('domain.test')
    spiffeid_1 = SpiffeId.of(trust_domain, 'path1')  # path1 is normalized as /path1
    spiffeid_2 = SpiffeId.of(trust_domain, '/path1')
    assert spiffeid_1 == spiffeid_2