test_validators.py 2.09 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
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)