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.from_segments(trust_domain, [path1, path2])
            assert str(spiffe_id
                       ) == 'spiffe://trustdomain' + '/' + path1 + '/' + path2
        else:
            with pytest.raises(SpiffeIdError) as exception:
                SpiffeId.from_segments('spiffe://trustdomain', [path1, path2])
            assert (
                str(exception.value) ==
                'Path segment characters are limited to letters, numbers, dots, dashes, and underscores.'
            )
def test_of_empty_trust_domain():
    with pytest.raises(ArgumentError) as exception:
        SpiffeId.from_segments('', '/path')

    assert str(exception.value) == 'Trust domain is missing.'
def test_not_equal_spiffe_ids():
    trust_domain = TrustDomain.parse('trustdomain')
    spiffeid_1 = SpiffeId.from_segments(trust_domain, '/path1')
    spiffeid_2 = SpiffeId.from_segments(trust_domain, '/path2')
    assert spiffeid_1 != spiffeid_2
def test_equal_spiffe_id_with_multiple_paths():
    trust_domain = TrustDomain.parse('trustdomain')
    spiffeid_1 = SpiffeId.from_segments(trust_domain, ['/PATH1', '/PATH2'])
    spiffeid_2 = SpiffeId.from_segments(trust_domain, ['/PATH1', '/PATH2'])
    assert spiffeid_1 == spiffeid_2
def test_of_trust_domain_and_invalid_segments(trust_domain, path_segments,
                                              expected_error):
    with pytest.raises(SpiffeIdError) as exception:
        SpiffeId.from_segments(trust_domain, path_segments)
    assert str(exception.value) == expected_error
def test_of_trust_domain_and_segments(trust_domain, path_segments,
                                      expected_spiffe_id):
    result = SpiffeId.from_segments(trust_domain, path_segments)
    assert str(result) == expected_spiffe_id