forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdomain-status.test.js
More file actions
202 lines (174 loc) · 6.41 KB
/
Copy pathdomain-status.test.js
File metadata and controls
202 lines (174 loc) · 6.41 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import { StatusEnum } from '../../../enums'
import { domainStatus } from '../domain-status'
describe('given the domainStatus object', () => {
describe('testing its field definitions', () => {
it('has a ciphers field', () => {
const demoType = domainStatus.getFields()
expect(demoType).toHaveProperty('ciphers')
expect(demoType.ciphers.type).toMatchObject(StatusEnum)
})
it('has a curves field', () => {
const demoType = domainStatus.getFields()
expect(demoType).toHaveProperty('curves')
expect(demoType.curves.type).toMatchObject(StatusEnum)
})
it('has a dkim field', () => {
const demoType = domainStatus.getFields()
expect(demoType).toHaveProperty('dkim')
expect(demoType.dkim.type).toMatchObject(StatusEnum)
})
it('has a dmarc field', () => {
const demoType = domainStatus.getFields()
expect(demoType).toHaveProperty('dmarc')
expect(demoType.dmarc.type).toMatchObject(StatusEnum)
})
it('has a https field', () => {
const demoType = domainStatus.getFields()
expect(demoType).toHaveProperty('https')
expect(demoType.https.type).toMatchObject(StatusEnum)
})
it('has a hsts field', () => {
const demoType = domainStatus.getFields()
expect(demoType).toHaveProperty('hsts')
expect(demoType.hsts.type).toMatchObject(StatusEnum)
})
it('has a policy field', () => {
const demoType = domainStatus.getFields()
expect(demoType).toHaveProperty('policy')
expect(demoType.policy.type).toMatchObject(StatusEnum)
})
it('has a protocols field', () => {
const demoType = domainStatus.getFields()
expect(demoType).toHaveProperty('protocols')
expect(demoType.protocols.type).toMatchObject(StatusEnum)
})
it('has a spf field', () => {
const demoType = domainStatus.getFields()
expect(demoType).toHaveProperty('spf')
expect(demoType.spf.type).toMatchObject(StatusEnum)
})
it('has a ssl field', () => {
const demoType = domainStatus.getFields()
expect(demoType).toHaveProperty('ssl')
expect(demoType.ssl.type).toMatchObject(StatusEnum)
})
})
describe('testing its field resolvers', () => {
describe('testing the ciphers resolver', () => {
it('returns the resolved value', () => {
const demoType = domainStatus.getFields()
expect(demoType.ciphers.resolve({ ciphers: 'pass' })).toEqual('pass')
})
})
describe('testing the curves resolver', () => {
it('returns the resolved value', () => {
const demoType = domainStatus.getFields()
expect(demoType.curves.resolve({ curves: 'pass' })).toEqual('pass')
})
})
describe('testing the dkim resolver', () => {
it('returns the resolved value', () => {
const demoType = domainStatus.getFields()
expect(demoType.dkim.resolve({ dkim: 'pass' })).toEqual('pass')
})
})
describe('testing the dmarc resolver', () => {
it('returns the resolved value', () => {
const demoType = domainStatus.getFields()
expect(demoType.dmarc.resolve({ dmarc: 'pass' })).toEqual('pass')
})
})
describe('testing the https resolver', () => {
it('returns the resolved value', () => {
const demoType = domainStatus.getFields()
expect(demoType.https.resolve({ https: 'pass' })).toEqual('pass')
})
})
describe('testing the hsts resolver', () => {
it('returns the resolved value', () => {
const demoType = domainStatus.getFields()
expect(demoType.hsts.resolve({ hsts: 'pass' })).toEqual('pass')
})
})
describe('testing the policy resolver', () => {
it('sets the policy field to pass if every component passes', () => {
const demoType = domainStatus.getFields()
const fields = {
ciphers: 'pass',
https: 'pass',
hsts: 'pass',
protocols: 'pass',
ssl: 'pass',
}
// All pass so policy passes
expect(demoType.policy.resolve(fields)).toEqual('pass')
// One fails so policy fails
Object.keys(fields).forEach((k) => {
const mutatedFields = Object.assign({}, fields)
mutatedFields[k] = 'fail'
expect(demoType.policy.resolve(mutatedFields)).toEqual('fail')
})
})
})
describe('testing the policy resolver', () => {
it('sets the policy field to pass if every component is info', () => {
const demoType = domainStatus.getFields()
const fields = {
ciphers: 'info',
https: 'info',
hsts: 'info',
protocols: 'info',
ssl: 'info',
}
// All info so policy passes
expect(demoType.policy.resolve(fields)).toEqual('pass')
// One fails so policy fails
Object.keys(fields).forEach((k) => {
const mutatedFields = Object.assign({}, fields)
mutatedFields[k] = 'fail'
expect(demoType.policy.resolve(mutatedFields)).toEqual('fail')
})
})
})
describe('testing the policy resolver', () => {
it('returns fail if any field fails', () => {
const demoType = domainStatus.getFields()
const fields = {
ciphers: 'info',
https: 'info',
hsts: 'fail',
protocols: 'info',
ssl: 'info',
}
// All info so policy passes
expect(demoType.policy.resolve(fields)).toEqual('fail')
// One fails so policy fails
Object.keys(fields).forEach((k) => {
const mutatedFields = Object.assign({}, fields)
mutatedFields[k] = 'fail'
expect(demoType.policy.resolve(mutatedFields)).toEqual('fail')
})
})
})
describe('testing the protocols resolver', () => {
it('returns the resolved value', () => {
const demoType = domainStatus.getFields()
expect(demoType.protocols.resolve({ protocols: 'pass' })).toEqual(
'pass',
)
})
})
describe('testing the spf resolver', () => {
it('returns the resolved value', () => {
const demoType = domainStatus.getFields()
expect(demoType.spf.resolve({ spf: 'pass' })).toEqual('pass')
})
})
describe('testing the ssl resolver', () => {
it('returns the resolved value', () => {
const demoType = domainStatus.getFields()
expect(demoType.ssl.resolve({ ssl: 'pass' })).toEqual('pass')
})
})
})
})