Commit 20e61fd9 authored by Martin Prudek's avatar Martin Prudek

TESTS: Add tests for input validators

parent 027a3453
import pytest
@pytest.fixture(params=[
"-----BEGIN CERTIFICATE REQUEST-----\n"
"MIHoMIGOAgEAMBsxGTAXBgNVBAMMEDAwMDAwMDBBMDAwMDAxRjMwWTATBgcqhkjO\n"
"PQIBBggqhkjOPQMBBwNCAAQo+Cq6N6QAu99pDw3GJGQ0NZIDnT/P9fU2FePZJVjU\n"
"o2obmdqZ/uRY8IeQOk3JvpoHM2o0621QIYvpjxxbOQSwoBEwDwYJKoZIhvcNAQkO\n"
"MQIwADAKBggqhkjOPQQDAgNJADBGAiEA9uJbjUc8CI2BAt7IO6LI6han20G2Ix9T\n"
"4mw2hEu3feECIQCb1yBuPIykwP896qq5ngESgDOi+AWUzcdVZpOMfVlIlg==\n"
"-----END CERTIFICATE REQUEST-----\n",
])
def good_csr(request):
return request.param
@pytest.fixture(params=[""])
def bad_csr(request):
return request.param
@pytest.fixture(params=[
(
"-----BEGIN CERTIFICATE REQUEST-----\n"
"MIHoMIGOAgEAMBsxGTAXBgNVBAMMEDAwMDAwMDBBMDAwMDAxRjMwWTATBgcqhkjO\n"
"PQIBBggqhkjOPQMBBwNCAAQo+Cq6N6QAu99pDw3GJGQ0NZIDnT/P9fU2FePZJVjU\n"
"o2obmdqZ/uRY8IeQOk3JvpoHM2o0621QIYvpjxxbOQSwoBEwDwYJKoZIhvcNAQkO\n"
"MQIwADAKBggqhkjOPQQDAgNJADBGAiEA9uJbjUc8CI2BAt7IO6LI6han20G2Ix9T\n"
"4mw2hEu3feECIQCb1yBuPIykwP896qq5ngESgDOi+AWUzcdVZpOMfVlIlg==\n"
"-----END CERTIFICATE REQUEST-----\n",
"0000000A000001F3",
),
])
def valid_csr_sn_sets(request):
return request.param
@pytest.fixture(params=[
"get_key",
"0000000A000001F4",
"1000000000000000",
""
])
def bad_sn_atsha(request):
return request.param
@pytest.fixture(params=[
"0000000A000001F3",
])
def good_sn_atsha(request):
return request.param
@pytest.fixture(params=[
"get_cert",
"auth",
])
def good_req_types(request):
return request.param
@pytest.fixture(params=[
"get_certs",
"",
" ",
None,
])
def bad_req_types(request):
return request.param
@pytest.fixture(params=[
["renew"],
[],
])
def good_flags(request):
return request.param
@pytest.fixture(params=[
["renw"],
[""],
[" "],
[None],
])
def bad_flags(request):
return request.param
@pytest.fixture(params=[
"atsha204",
])
def good_auth_types(request):
return request.param
@pytest.fixture(params=[
"atsha",
"",
" ",
None,
# TODO: improve cert-spi so these lines can ba added to tests
# ["atsha"],
# ["atsha204"],
# [],
])
def bad_auth_types(request):
return request.param
@pytest.fixture(params=[
"06d2bce6a9a1423629e93d451e51f156c6f9c556e495ce6506b2f93ba7e9a5c0",
"adc619eeb5f1d98873c42d19d69e9cf85e84080b54d8b565dc7e789ce9542772",
"",
])
def good_sid(request):
return request.param
@pytest.fixture(params=[
"atsha",
"Adc619eeb5f1d98873c42d19d69e9cf85e84080b54d8b565dc7e789ce9542772",
"dc619eeb5f1d98873c42d19d69e9cf85e84080b54d8b565dc7e789ce9542772",
"adc619eeb5f1d98873c42d19d69e9cf85e84080b54d8b565dc7e789ce954277",
" ",
# TODO: improve cert-spi so these lines can ba added to tests
# ["adc619eeb5f1d98873c42d19d69e9cf85e84080b54d8b565dc7e789ce9542772"],
# None,
# [],
])
def bad_sid(request):
return request.param
@pytest.fixture(params=[
{
"auth_type",
"nonce",
"digest",
"csr_str",
"flags",
}
])
def good_sessions(request):
return request.param
@pytest.fixture(params=[
{
"auth_type",
"nonce",
"digest",
"csr_str",
"",
},
{
"auth_type",
"nonce",
"digest",
"csr_str",
"flagss",
},
{
"auth_type",
"nonce",
"digest",
"csr_str",
},
{}
])
def bad_sessions(request):
return request.param
@pytest.fixture(params=[
(
"status",
),
(
"status",
)
])
def good_auth_state(request):
return request.param
@pytest.fixture(params=[
(
"statu",
"echo"
),
(
"",
"echo"
),
# ( # TODO: improve cert-spi so these lines can ba added to tests
# "status",
# "echo"
# ),
# (
# "status",
# "status"
# ),
(
"",
),
(
),
])
def bad_auth_state(request):
return request.param
import pytest
import certapi.crypto as c
import certapi.validators as v
import certapi.exceptions as ex
def test_valid_sn_atsha(good_sn_atsha):
v.validate_sn_atsha(good_sn_atsha)
def test_invalid_sn_atsha(bad_sn_atsha):
with pytest.raises(ex.InvalidParamError):
v.validate_sn_atsha(bad_sn_atsha)
def test_valid_csr_common_name(valid_csr_sn_sets):
csr = c.csr_from_str(valid_csr_sn_sets[0])
v.validate_csr_common_name(csr, valid_csr_sn_sets[1])
def test_valid_csr_hash(good_csr):
csr = c.csr_from_str(good_csr)
v.validate_csr_hash(csr)
def test_valid_csr_signature(good_csr):
csr = c.csr_from_str(good_csr)
v.validate_csr_signature(csr)
def test_valid_csr(good_csr, good_sn_atsha):
v.validate_csr(good_csr, good_sn_atsha)
def test_invalid_csr(bad_csr, bad_sn_atsha):
with pytest.raises(ex.InvalidParamError):
v.validate_csr(bad_csr, bad_sn_atsha)
def test_valid_req_type(good_req_types):
v.validate_req_type(good_req_types)
def test_invalid_req_type(bad_req_types):
with pytest.raises(ex.InvalidParamError):
v.validate_req_type(bad_req_types)
def test_valid_flags(good_flags):
v.validate_flags(good_flags)
def test_invalid_flags(bad_flags):
with pytest.raises(ex.InvalidParamError):
v.validate_flags(bad_flags)
def test_valid_auth_type(good_auth_types):
v.validate_auth_type(good_auth_types)
def test_invalid_auth_type(bad_auth_types):
with pytest.raises(ex.InvalidParamError):
v.validate_auth_type(bad_auth_types)
def test_valid_sn(good_sid):
v.validate_sid(good_sid)
def test_invalid_sn(bad_sid):
with pytest.raises(ex.InvalidParamError):
v.validate_sid(bad_sid)
def test_valid_session(good_sessions):
v.check_session(good_sessions)
def test_invalid_session(bad_sessions):
with pytest.raises(ex.InvalidSessionError):
v.check_session(bad_sessions)
def test_valid_auth_state(good_auth_state):
v.check_auth_state(good_auth_state)
def test_invalid_auth_state(bad_auth_state):
with pytest.raises(ex.InvalidAuthStateError):
v.check_auth_state(bad_auth_state)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment