@@ -11,97 +11,98 @@ describe('DirectiveMap.get()',() => {
11
11
describe ( 'Dynamic Options' , ( ) => {
12
12
it ( 'Handles Hostname/URL Source' , ( ) => {
13
13
const src = DirectiveMap . get ( 'child-src' ) ;
14
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
- const start : any = undefined ;
16
- const result = src ?. values . reduce ( ( _ , v ) => {
14
+ let result1 : unknown = '' ;
15
+ let result2 : unknown = '' ;
16
+ for ( const item of src ?. values || [ ] ) {
17
17
if (
18
- isObject ( v ) &&
19
- hasOwnProperty ( v , 'displayName' ) &&
20
- v . displayName === 'Hostname/URL Source'
18
+ isObject ( item ) &&
19
+ hasOwnProperty ( item , 'displayName' ) &&
20
+ item . displayName === 'Hostname/URL Source'
21
21
) {
22
- return v ? .compose ?.( {
22
+ result1 = item . compose ?.( {
23
23
'Hostname' : 'example.com' ,
24
24
'Port' : 443 ,
25
25
'Protocol' :'https://' ,
26
26
} ) ;
27
27
}
28
- return _ ;
29
- } , start ) ;
30
- expect ( result ) . toBe ( 'https://example.com:443' ) ;
28
+ }
29
+ for ( const item of src ?. values || [ ] ) {
30
+ if (
31
+ isObject ( item ) &&
32
+ hasOwnProperty ( item , 'displayName' ) &&
33
+ item . displayName === 'Hostname/URL Source'
34
+ ) {
35
+ result2 = item . compose ?.( { } ) ;
36
+ }
37
+ }
38
+ expect ( result1 ) . toBe ( 'https://example.com:443' ) ;
39
+ expect ( result2 ) . toBe ( '' ) ;
31
40
} ) ;
32
41
it ( 'Crypto Nonce/Hash Source' , ( ) => {
33
42
const src = DirectiveMap . get ( 'child-src' ) ;
34
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
- const start : any = undefined ;
36
- const result = src ?. values . reduce ( ( _ , v ) => {
43
+ let result : unknown = '' ;
44
+ for ( const item of src ?. values || [ ] ) {
37
45
if (
38
- isObject ( v ) &&
39
- hasOwnProperty ( v , 'displayName' ) &&
40
- v . displayName === 'Crypto Nonce/Hash Source'
46
+ isObject ( item ) &&
47
+ hasOwnProperty ( item , 'displayName' ) &&
48
+ item . displayName === 'Crypto Nonce/Hash Source'
41
49
) {
42
- return v ? .compose ?.( {
50
+ result = item . compose ?.( {
43
51
'Algorithm' :'sha256' ,
44
52
'Hash' :'SomeBase64String' ,
45
53
} ) ;
46
54
}
47
- return _ ;
48
- } , start ) ;
55
+ }
49
56
expect ( result ) . toBe ( 'sha256-SomeBase64String' ) ;
50
57
} ) ;
51
58
it ( 'Handles URI Source' , ( ) => {
52
- const src = DirectiveMap . get ( 'child-src' ) ;
53
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
54
- const start : any = undefined ;
55
- const result = src ?. values . reduce ( ( _ , v ) => {
59
+ const src = DirectiveMap . get ( 'report-uri' ) ;
60
+ let result : unknown = '' ;
61
+ for ( const item of src ?. values || [ ] ) {
56
62
if (
57
- isObject ( v ) &&
58
- hasOwnProperty ( v , 'displayName' ) &&
59
- v . displayName === 'URI Source'
63
+ isObject ( item ) &&
64
+ hasOwnProperty ( item , 'displayName' ) &&
65
+ item . displayName === 'URI Source'
60
66
) {
61
- return v ? .compose ?.( {
67
+ result = item . compose ?.( {
62
68
'Beginning Delineator' :'/' ,
63
69
'Remaining Path' :'send/reports/to' ,
64
70
} ) ;
65
71
}
66
- return _ ;
67
- } , start ) ;
72
+ }
68
73
expect ( result ) . toBe ( '/send/reports/to' ) ;
69
74
} ) ;
70
75
it ( 'Handles Plugin MIME Type Source' , ( ) => {
71
- const src = DirectiveMap . get ( 'child-src' ) ;
72
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
73
- const start : any = undefined ;
74
- const result = src ?. values . reduce ( ( _ , v ) => {
76
+ const src = DirectiveMap . get ( 'plugin-types' ) ;
77
+ let result : unknown = '' ;
78
+ for ( const item of src ?. values || [ ] ) {
75
79
if (
76
- isObject ( v ) &&
77
- hasOwnProperty ( v , 'displayName' ) &&
78
- v . displayName === 'Plugin MIME Type Source'
80
+ isObject ( item ) &&
81
+ hasOwnProperty ( item , 'displayName' ) &&
82
+ item . displayName === 'Plugin MIME Type Source'
79
83
) {
80
- return v ? .compose ?.( {
84
+ result = item . compose ?.( {
81
85
'MIME Category' :'application' ,
82
86
'MIME Implementation' :'xml' ,
83
87
} ) ;
84
88
}
85
- return _ ;
86
- } , start ) ;
89
+ }
87
90
expect ( result ) . toBe ( 'application/xml' ) ;
88
91
} ) ;
89
92
it ( 'Handles Any String' , ( ) => {
90
- const src = DirectiveMap . get ( 'child-src' ) ;
91
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
92
- const start : any = undefined ;
93
- const result = src ?. values . reduce ( ( _ , v ) => {
93
+ const src = DirectiveMap . get ( 'report-to' ) ;
94
+ let result : unknown = '' ;
95
+ for ( const item of src ?. values || [ ] ) {
94
96
if (
95
- isObject ( v ) &&
96
- hasOwnProperty ( v , 'displayName' ) &&
97
- v . displayName === 'Any String'
97
+ isObject ( item ) &&
98
+ hasOwnProperty ( item , 'displayName' ) &&
99
+ item . displayName === 'Any String'
98
100
) {
99
- return v ? .compose ?.( {
101
+ result = item . compose ?.( {
100
102
'String' :'hello world' ,
101
103
} ) ;
102
104
}
103
- return _ ;
104
- } , start ) ;
105
+ }
105
106
expect ( result ) . toBe ( 'hello world' ) ;
106
107
} ) ;
107
108
} ) ;
0 commit comments