-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverifiedAttributes.test.ts
More file actions
196 lines (182 loc) · 6.43 KB
/
Copy pathverifiedAttributes.test.ts
File metadata and controls
196 lines (182 loc) · 6.43 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
import { describe, it, expect } from 'vitest'
import {
isUnsignedSender,
isWeakSenderIdentity,
verifiedAttributesFor,
} from './verifiedAttributes'
import type { FriendlySender } from '@e4a/pg-js'
const sender = (attrs: { type: string; value?: string }[]): FriendlySender => ({
email: attrs.find((a) => a.type.includes('email'))?.value ?? null,
attributes: attrs,
raw: {
public: {
con: attrs
.filter((a) => a.type.includes('email'))
.map((a) => ({ t: a.type, v: a.value })),
},
private: {
con: attrs
.filter((a) => !a.type.includes('email'))
.map((a) => ({ t: a.type, v: a.value })),
},
},
})
describe('verifiedAttributesFor', () => {
it('returns an empty list when sender is null or undefined', () => {
expect(verifiedAttributesFor(null)).toEqual([])
expect(verifiedAttributesFor(undefined)).toEqual([])
})
it('returns each non-email attribute with its i18n label key and value', () => {
const result = verifiedAttributesFor(
sender([
{ type: 'pbdf.sidn-pbdf.email.email', value: 'a@b.com' },
{
type: 'pbdf.gemeente.personalData.fullname',
value: 'R.A. Hensen',
},
{
type: 'pbdf.sidn-pbdf.mobilenumber.mobilenumber',
value: '+31630222348',
},
{
type: 'pbdf.gemeente.personalData.dateofbirth',
value: '27-05-1996',
},
])
)
expect(result).toEqual([
{
type: 'pbdf.gemeente.personalData.fullname',
labelKey:
'filesharing.attributes.pbdf.gemeente.personalData.fullname',
value: 'R.A. Hensen',
},
{
type: 'pbdf.sidn-pbdf.mobilenumber.mobilenumber',
labelKey:
'filesharing.attributes.pbdf.sidn-pbdf.mobilenumber.mobilenumber',
value: '+31630222348',
},
{
type: 'pbdf.gemeente.personalData.dateofbirth',
labelKey:
'filesharing.attributes.pbdf.gemeente.personalData.dateofbirth',
value: '27-05-1996',
},
])
})
it('drops attributes whose value is missing or empty', () => {
const result = verifiedAttributesFor(
sender([
{ type: 'pbdf.sidn-pbdf.email.email', value: 'a@b.com' },
{
type: 'pbdf.gemeente.personalData.fullname',
value: 'R.A. Hensen',
},
{
type: 'pbdf.sidn-pbdf.mobilenumber.mobilenumber',
value: undefined,
},
])
)
expect(result.map((r) => r.type)).toEqual([
'pbdf.gemeente.personalData.fullname',
])
})
it('returns an empty list when the sender only disclosed email', () => {
const result = verifiedAttributesFor(
sender([{ type: 'pbdf.sidn-pbdf.email.email', value: 'a@b.com' }])
)
expect(result).toEqual([])
})
})
describe('isWeakSenderIdentity', () => {
it('does not treat a missing sender as email-only weak', () => {
// An unsigned file has no email to caveat, so the email-only
// warning copy does not apply — flagging it would be inaccurate.
expect(isWeakSenderIdentity(null)).toBe(false)
expect(isWeakSenderIdentity(undefined)).toBe(false)
})
it('does not treat a sender with no verified email as email-only weak', () => {
// No email and nothing else disclosed: there is no email claim to
// warn about, so this is not the email-only case.
expect(isWeakSenderIdentity(sender([]))).toBe(false)
})
it('treats an email-only sender as weak', () => {
expect(
isWeakSenderIdentity(
sender([
{
type: 'pbdf.sidn-pbdf.email.email',
value: 'a@b.com',
},
])
)
).toBe(true)
})
it('treats a sender with any verified non-email attribute as strong', () => {
expect(
isWeakSenderIdentity(
sender([
{
type: 'pbdf.sidn-pbdf.email.email',
value: 'a@b.com',
},
{
type: 'pbdf.gemeente.personalData.fullname',
value: 'R.A. Hensen',
},
])
)
).toBe(false)
})
it('ignores non-email attributes whose value is empty', () => {
// An attribute type without a value carries no signal — it must
// not flip the gate from "weak" to "strong".
expect(
isWeakSenderIdentity(
sender([
{
type: 'pbdf.sidn-pbdf.email.email',
value: 'a@b.com',
},
{
type: 'pbdf.gemeente.personalData.fullname',
value: undefined,
},
])
)
).toBe(true)
})
})
describe('isUnsignedSender', () => {
it('treats a missing sender as unsigned', () => {
expect(isUnsignedSender(null)).toBe(true)
expect(isUnsignedSender(undefined)).toBe(true)
})
it('treats a sender with no verified email as unsigned', () => {
expect(isUnsignedSender(sender([]))).toBe(true)
})
it('does not treat an email-only sender as unsigned', () => {
expect(
isUnsignedSender(
sender([
{ type: 'pbdf.sidn-pbdf.email.email', value: 'a@b.com' },
])
)
).toBe(false)
})
it('does not treat a fully verified sender as unsigned', () => {
expect(
isUnsignedSender(
sender([
{ type: 'pbdf.sidn-pbdf.email.email', value: 'a@b.com' },
{
type: 'pbdf.gemeente.personalData.fullname',
value: 'R.A. Hensen',
},
])
)
).toBe(false)
})
})