Projekt

Obecné

Profil

Stáhnout (4.41 KB) Statistiky
| Větev: | Tag: | Revize:
1 a0d4dda1 Captain_Trojan
def test_import(server):
2
    assert 1 + 2 + 3 + 4 != -1 / 12
3
4
    ret = server.get("/")
5
    assert ret.status_code == 404
6
7
8
def test_root_ca(server):
9
    ret = server.post("/api/certificates", content_type="application/json", json={
10
        "subject": {
11
            "C": "CZ",
12
            "CN": "Root CA s.r.o.",
13
            "L": "Pilsen",
14
            "O": "Root CA s.r.o.",
15
            "OU": "IT department",
16
            "ST": "Pilsen Region",
17
            "emailAddress": "root@ca.com"
18
        },
19
        "usage": {
20
            "CA": True,
21
            "SSL": True,
22
            "authentication": True,
23
            "digitalSignature": True
24
        },
25
        "validityDays": 30
26
    })
27
28
    assert ret.status_code == 201
29
30
    d = ret.json
31
32
    assert "data" in d
33
    assert d["data"] == 1
34
    assert "success" in d
35
    assert d["success"]
36
37
38
def test_invalid_params_1(server):
39
    ret = server.post("/api/certificates", content_type="application/json", json={
40
        "subject": {
41
            "C": "CZ",
42
            "CN": "Root CA s.r.o.",
43
            "L": "Pilsen",
44
            "O": "Root CA s.r.o.",
45
            "OU": "IT department",
46
            "ST": "Pilsen Region",
47
            "emailAddress": "root@ca.com"
48
        },
49
        "validityDays": 30
50
    })
51
52
    assert ret.status_code == 400
53
54
    d = ret.json
55
56
    assert "status" in d
57
    assert d["status"] == 400
58
    assert "detail" in d
59
    assert d["detail"] == "'usage' is a required property"
60
61
62
def test_invalid_params_2(server):
63
    ret = server.post("/api/certificates", content_type="application/json", json={
64
        "subject": {
65
            "C": "CZ",
66
            "CN": "Root CA s.r.o.",
67
            "L": "Pilsen",
68
            "O": "Root CA s.r.o.",
69
            "OU": "IT department",
70
            "ST": "Pilsen Region",
71
            "emailAddress": "root@ca.com"
72
        },
73
        "usage": {
74
            "CA": True,
75
            "SSL": True,
76
            "authentication": True,
77
            "digitalSignature": True
78
        },
79
        "validityDays": "tak mesic treba plus minus"
80
    })
81
82
    assert ret.status_code == 400
83
84
    d = ret.json
85
86
    assert "status" in d
87
    assert d["status"] == 400
88
    assert "detail" in d
89
    assert d["detail"] == "'tak mesic treba plus minus' is not of type 'integer' - 'validityDays'"
90
91
92
def test_invalid_params_3(server):
93
    ret = server.post("/api/certificates", content_type="application/json", json={
94
        "subject": {
95
            "C": "CZ",
96
            "CN": "Root CA s.r.o.",
97
            "L": "Pilsen",
98
            "O": "Root CA s.r.o.",
99
            "OU": "IT department",
100
            "ST": ["Bosna", "Herzegovina"],
101
            "emailAddress": "root@ca.com"
102
        },
103
        "usage": {
104
            "CA": True,
105
            "SSL": True,
106
            "authentication": True,
107
            "digitalSignature": True
108
        },
109
        "validityDays": 30
110
    })
111
112
    assert ret.status_code == 400
113
114
    d = ret.json
115
116
    assert "status" in d
117
    assert d["status"] == 400
118
    assert "detail" in d
119
    assert d["detail"] == "['Bosna', 'Herzegovina'] is not of type 'string' - 'subject.ST'"
120
121
122
def test_root_inter_ca(server):
123
    ret = server.post("/api/certificates", content_type="application/json", json={
124
        "subject": {
125
            "C": "CZ",
126
            "CN": "Root CA s.r.o.",
127
            "L": "Pilsen",
128
            "O": "Root CA s.r.o.",
129
            "OU": "IT department",
130
            "ST": "Pilsen Region",
131
            "emailAddress": "root@ca.com"
132
        },
133
        "usage": {
134
            "CA": True,
135
            "SSL": True,
136
            "authentication": True,
137
            "digitalSignature": True
138
        },
139
        "validityDays": 30
140
    })
141
142
    assert ret.status_code == 201
143
144
    d = ret.json
145
146
    assert "data" in d
147
    assert d["data"] == 2
148
    assert "success" in d
149
    assert d["success"]
150
151
    ret = server.post("/api/certificates", content_type="application/json", json={
152
        "subject": {
153
            "CA": 2,
154
            "C": "CZ",
155
            "CN": "Root CA s.r.o.",
156
            "L": "Pilsen",
157
            "O": "Root CA s.r.o.",
158
            "OU": "IT department",
159
            "ST": "Pilsen Region",
160
            "emailAddress": "root@ca.com"
161
        },
162
        "usage": {
163
            "CA": True,
164
            "SSL": True,
165
            "authentication": True,
166
            "digitalSignature": True
167
        },
168
        "validityDays": 30
169
    })
170
171
    assert ret.status_code == 201
172
173
    d = ret.json
174
175
    assert "data" in d
176
    assert d["data"] == 3
177
    assert "success" in d
178
    assert d["success"]