@@ -2132,6 +2132,210 @@ Tried mapping @id to {}`, ERROR_CODES.KEYWORD_REDEFINITION));
2132
2132
} ) ) ;
2133
2133
} ) ;
2134
2134
2135
+ it ( 'should parse 2 contexts where one is protected' , ( ) => {
2136
+ return expect ( parser . parse ( [
2137
+ {
2138
+ "@version" : 1.0 ,
2139
+ "ex" :"https://example.org/ns/"
2140
+ } ,
2141
+ {
2142
+ "@version" : 1.1 ,
2143
+ "@protected" : true ,
2144
+ "VerifiableCredential" : {
2145
+ "@id" : "https://www.w3.org/2018/credentials#VerifiableCredential" ,
2146
+ }
2147
+ }
2148
+ ] ) ) . resolves . toEqual ( new JsonLdContextNormalized ( {
2149
+ "@version" : 1.1 ,
2150
+ VerifiableCredential : {
2151
+ "@id" : "https://www.w3.org/2018/credentials#VerifiableCredential" ,
2152
+ "@protected" : true ,
2153
+ } ,
2154
+ ex : "https://example.org/ns/"
2155
+ } ) ) ;
2156
+ } ) ;
2157
+
2158
+ const contexts = [
2159
+ {
2160
+ "@version" : 1.1 ,
2161
+ "@protected" : true ,
2162
+ "VerifiableCredential" : {
2163
+ "@id" : "https://www.w3.org/2018/credentials#VerifiableCredential" ,
2164
+ }
2165
+ } ,
2166
+ {
2167
+ "ex" :"https://example.org/ns/" ,
2168
+ "@version" : 1.1 ,
2169
+ "@protected" : false ,
2170
+ }
2171
+ ] ;
2172
+
2173
+ const result = new JsonLdContextNormalized ( {
2174
+ "@version" : 1.1 ,
2175
+ "@protected" : false ,
2176
+ VerifiableCredential : {
2177
+ "@id" : "https://www.w3.org/2018/credentials#VerifiableCredential" ,
2178
+ "@protected" : true ,
2179
+ } ,
2180
+ ex : "https://example.org/ns/"
2181
+ } ) ;
2182
+
2183
+ it ( 'should parse 2 contexts where one is protected and one globally has protected false' , ( ) => {
2184
+ return expect ( parser . parse ( contexts ) ) . resolves . toEqual ( result ) ;
2185
+ } ) ;
2186
+
2187
+ it ( 'should parse 2 contexts where one is protected and one globally has protected false [reverse order]' , ( ) => {
2188
+ return expect ( parser . parse ( [ contexts [ 1 ] , contexts [ 0 ] ] ) ) . resolves . toEqual ( result ) ;
2189
+ } ) ;
2190
+
2191
+ const BASIC_VC_CONTEXT = {
2192
+ "@version" : 1.1 ,
2193
+ "@protected" : true ,
2194
+ "VerifiableCredential" : {
2195
+ "@id" : "https://www.w3.org/2018/credentials#VerifiableCredential" ,
2196
+ }
2197
+ }
2198
+
2199
+ it ( 'protected context should override the unprotected context' , ( ) => {
2200
+ return expect ( parser . parse ( [
2201
+ {
2202
+ "@version" : 1.0 ,
2203
+ "VerifiableCredential" :"https://example.org/ns/"
2204
+ } ,
2205
+ BASIC_VC_CONTEXT
2206
+ ] ) ) . resolves . toEqual ( new JsonLdContextNormalized ( {
2207
+ "@version" : 1.1 ,
2208
+ VerifiableCredential : {
2209
+ "@id" : "https://www.w3.org/2018/credentials#VerifiableCredential" ,
2210
+ "@protected" : true ,
2211
+ }
2212
+ } ) ) ;
2213
+ } ) ;
2214
+
2215
+ describe ( 'with imported contexts' , ( ) => {
2216
+ beforeEach ( ( ) => {
2217
+ jest . mocked ( globalThis . fetch ) . mockImplementationOnce ( async ( ...args ) => {
2218
+ return new Response ( JSON . stringify ( {
2219
+ "@context" : {
2220
+ "MyType" : {
2221
+ "@id" : "http://example.org#MyType" ,
2222
+ }
2223
+ }
2224
+ } ) , { headers : new Headers ( [
2225
+ [ 'content-type' , 'application/ld+json' ]
2226
+ ] ) } )
2227
+ } ) ;
2228
+ } ) ;
2229
+
2230
+ it ( 'protected should be applied to the imported context' , ( ) => {
2231
+ return expect ( parser . parse ( [
2232
+ {
2233
+ ...BASIC_VC_CONTEXT ,
2234
+ "@import" : "http://example.org/imported/context"
2235
+ }
2236
+ ] ) ) . resolves . toEqual ( new JsonLdContextNormalized ( {
2237
+ "@version" : 1.1 ,
2238
+ VerifiableCredential : {
2239
+ "@id" : "https://www.w3.org/2018/credentials#VerifiableCredential" ,
2240
+ "@protected" : true ,
2241
+ } ,
2242
+ MyType : {
2243
+ "@id" : "http://example.org#MyType" ,
2244
+ "@protected" : true ,
2245
+ }
2246
+ } ) ) ;
2247
+ } ) ;
2248
+
2249
+ it . each ( [
2250
+ [ 'child' , [ BASIC_VC_CONTEXT , { "@import" : "http://example.org/imported/context" } ] ] ,
2251
+ [ 'parent' , [ { "@import" : "http://example.org/imported/context" } , BASIC_VC_CONTEXT ] ] ,
2252
+ ] ) ( 'protected should not be applied to the imported contexts in other %s contexts' , ( _ , context ) => {
2253
+ return expect ( parser . parse ( context ) ) . resolves . toEqual ( new JsonLdContextNormalized ( {
2254
+ "@version" : 1.1 ,
2255
+ VerifiableCredential : {
2256
+ "@id" : "https://www.w3.org/2018/credentials#VerifiableCredential" ,
2257
+ "@protected" : true ,
2258
+ } ,
2259
+ MyType : { "@id" : "http://example.org#MyType" }
2260
+ } ) ) ;
2261
+ } ) ;
2262
+ } ) ;
2263
+
2264
+
2265
+ describe ( 'with imported contexts containing the @protected keyword' , ( ) => {
2266
+
2267
+ const BASIC_VC_CONTEXT_WITHOUT_PROTECTED = {
2268
+ "@version" : 1.1 ,
2269
+ "VerifiableCredential" : {
2270
+ "@id" : "https://www.w3.org/2018/credentials#VerifiableCredential" ,
2271
+ }
2272
+ }
2273
+
2274
+ beforeEach ( ( ) => {
2275
+ jest . mocked ( globalThis . fetch ) . mockImplementationOnce ( async ( ...args ) => {
2276
+ return new Response ( JSON . stringify ( {
2277
+ "@context" : {
2278
+ "@protected" : true ,
2279
+ "MyType" : "http://example.org#MyType"
2280
+ }
2281
+ } ) , { headers : new Headers ( [
2282
+ [ 'content-type' , 'application/ld+json' ]
2283
+ ] ) } )
2284
+ } ) ;
2285
+ } ) ;
2286
+
2287
+ it ( 'protected should be applied to the imported context' , ( ) => {
2288
+ return expect ( parser . parse ( [
2289
+ {
2290
+ ...BASIC_VC_CONTEXT_WITHOUT_PROTECTED ,
2291
+ "@import" : "http://example.org/imported/context"
2292
+ }
2293
+ ] ) ) . resolves . toEqual ( new JsonLdContextNormalized ( {
2294
+ "@version" : 1.1 ,
2295
+ VerifiableCredential : {
2296
+ "@id" : "https://www.w3.org/2018/credentials#VerifiableCredential" ,
2297
+ } ,
2298
+ MyType : {
2299
+ "@id" : "http://example.org#MyType" ,
2300
+ "@protected" : true ,
2301
+ }
2302
+ } ) ) ;
2303
+ } ) ;
2304
+
2305
+ it . each ( [
2306
+ [ 'child' , [ BASIC_VC_CONTEXT_WITHOUT_PROTECTED , { "@import" : "http://example.org/imported/context" } ] ] ,
2307
+ [ 'parent' , [ { "@import" : "http://example.org/imported/context" } , BASIC_VC_CONTEXT_WITHOUT_PROTECTED ] ] ,
2308
+ ] ) ( 'protected should not be applied to the imported contexts in other %s contexts' , ( _ , context ) => {
2309
+ return expect ( parser . parse ( context ) ) . resolves . toEqual ( new JsonLdContextNormalized ( {
2310
+ "@version" : 1.1 ,
2311
+ VerifiableCredential : {
2312
+ "@id" : "https://www.w3.org/2018/credentials#VerifiableCredential" ,
2313
+ } ,
2314
+ MyType : { "@id" : "http://example.org#MyType" , "@protected" : true }
2315
+ } ) ) ;
2316
+ } ) ;
2317
+ } ) ;
2318
+
2319
+ it ( 'should parse 2 contexts where one is protected' , ( ) => {
2320
+ return expect ( parser . parse ( [
2321
+ { "ex" :"https://example.org/ns/" } ,
2322
+ {
2323
+ "@version" : 1.1 ,
2324
+ "@protected" : true ,
2325
+ "VerifiableCredential" : {
2326
+ "@id" : "https://www.w3.org/2018/credentials#VerifiableCredential" ,
2327
+ }
2328
+ }
2329
+ ] ) ) . resolves . toEqual ( new JsonLdContextNormalized ( {
2330
+ "@version" : 1.1 ,
2331
+ VerifiableCredential : {
2332
+ "@id" : "https://www.w3.org/2018/credentials#VerifiableCredential" ,
2333
+ "@protected" : true ,
2334
+ } ,
2335
+ ex : "https://example.org/ns/"
2336
+ } ) ) ;
2337
+ } ) ;
2338
+
2135
2339
it ( 'should parse a single keyword alias' , ( ) => {
2136
2340
return expect ( parser . parse ( {
2137
2341
id : {
@@ -2214,6 +2418,60 @@ Tried mapping @id to {}`, ERROR_CODES.KEYWORD_REDEFINITION));
2214
2418
ERROR_CODES . PROTECTED_TERM_REDEFINITION ) ) ;
2215
2419
} ) ;
2216
2420
2421
+ it ( 'should error on a protected term with override when the overriding version is 1.0' , ( ) => {
2422
+ return expect ( parser . parse ( [
2423
+ {
2424
+ name : {
2425
+ '@id' : 'http://xmlns.com/foaf/0.1/name' ,
2426
+ '@protected' : true ,
2427
+ } ,
2428
+ } ,
2429
+ {
2430
+ "@version" : 1.0 ,
2431
+ name : 'http://schema.org/name' ,
2432
+ } ,
2433
+ ] ) ) . rejects . toThrow ( new ErrorCoded (
2434
+ 'Attempted to override the protected keyword name from ' +
2435
+ '"http://xmlns.com/foaf/0.1/name" to "http://schema.org/name"' ,
2436
+ ERROR_CODES . PROTECTED_TERM_REDEFINITION ) ) ;
2437
+ } ) ;
2438
+
2439
+ it ( 'should error on an outer scope protected term with override of another protected term' , ( ) => {
2440
+ return expect ( parser . parse ( [
2441
+ {
2442
+ "VerifiableCredential" :"https://example.org/ns/" ,
2443
+ "@protected" : true
2444
+ } ,
2445
+ {
2446
+ "@version" : 1.1 ,
2447
+ "@protected" : true ,
2448
+ "VerifiableCredential" : {
2449
+ "@id" : "https://www.w3.org/2018/credentials#VerifiableCredential" ,
2450
+ }
2451
+ }
2452
+ ] , { processingMode : 1.1 } ) ) . rejects . toThrow ( new ErrorCoded (
2453
+ 'Attempted to override the protected keyword VerifiableCredential from ' +
2454
+ '"https://example.org/ns/" to "https://www.w3.org/2018/credentials#VerifiableCredential"' ,
2455
+ ERROR_CODES . PROTECTED_TERM_REDEFINITION ) ) ;
2456
+ } ) ;
2457
+
2458
+ it ( 'should error on an outer scope protected term with override' , ( ) => {
2459
+ return expect ( parser . parse ( [
2460
+ {
2461
+ '@protected' : true ,
2462
+ name : {
2463
+ '@id' : 'http://xmlns.com/foaf/0.1/name' ,
2464
+ } ,
2465
+ } ,
2466
+ {
2467
+ name : 'http://schema.org/name' ,
2468
+ } ,
2469
+ ] , { processingMode : 1.1 } ) ) . rejects . toThrow ( new ErrorCoded (
2470
+ 'Attempted to override the protected keyword name from ' +
2471
+ '"http://xmlns.com/foaf/0.1/name" to "http://schema.org/name"' ,
2472
+ ERROR_CODES . PROTECTED_TERM_REDEFINITION ) ) ;
2473
+ } ) ;
2474
+
2217
2475
it ( 'should not error on a protected term with override if ignoreProtection is true' , ( ) => {
2218
2476
return expect ( parser . parse ( [
2219
2477
{
@@ -2482,6 +2740,21 @@ Tried mapping @id to {}`, ERROR_CODES.KEYWORD_REDEFINITION));
2482
2740
} ) ) ;
2483
2741
} ) ;
2484
2742
2743
+ it ( 'should parse a globally protected string term ending in gen-delim' , ( ) => {
2744
+ return expect ( parser . parse ( [
2745
+ {
2746
+ '@protected' : true ,
2747
+ 'foo' : 'http://example/foo#' ,
2748
+ }
2749
+ ] , { processingMode : 1.1 } ) ) . resolves . toEqual ( new JsonLdContextNormalized ( {
2750
+ foo : {
2751
+ '@id' : 'http://example/foo#' ,
2752
+ '@prefix' : true ,
2753
+ '@protected' : true ,
2754
+ } ,
2755
+ } ) ) ;
2756
+ } ) ;
2757
+
2485
2758
it ( 'should parse a globally protected string term ending in non-gen-delim with identical override' , ( ) => {
2486
2759
return expect ( parser . parse ( [
2487
2760
{
@@ -2623,6 +2896,7 @@ Tried mapping @id to {}`, ERROR_CODES.KEYWORD_REDEFINITION));
2623
2896
"@base" : "http://base.org/" ,
2624
2897
"ex" : {
2625
2898
"@id" : "http://ex.org/" ,
2899
+ "@prefix" : true ,
2626
2900
"@protected" : true
2627
2901
} ,
2628
2902
"foo" : {
0 commit comments