@@ -270,6 +270,44 @@ const unionFieldSchema = `
270270 "version": "1"
271271}` ;
272272
273+ const complexNestedSchema = `
274+ {
275+ "type": "record",
276+ "name": "UnionTest",
277+ "namespace": "test",
278+ "fields": [
279+ {
280+ "name": "emails",
281+ "type": [
282+ "null",
283+ {
284+ "type": "array",
285+ "items": {
286+ "type": "record",
287+ "name": "Email",
288+ "fields": [
289+ {
290+ "name": "email",
291+ "type": [
292+ "null",
293+ "string"
294+ ],
295+ "doc": "Email address",
296+ "default": null,
297+ "confluent:tags": [
298+ "PII"
299+ ]
300+ }
301+ ]
302+ }
303+ }
304+ ],
305+ "doc": "Communication Email",
306+ "default": null
307+ }
308+ ]
309+ }` ;
310+
273311class FakeClock extends Clock {
274312 fixedNow : number = 0
275313
@@ -1358,6 +1396,63 @@ describe('AvroSerializer', () => {
13581396 expect ( obj2 . mapField ) . toEqual ( { 'key' : 'world' } ) ;
13591397 expect ( obj2 . unionField ) . toEqual ( null ) ;
13601398 } )
1399+ it ( 'complex nested encryption' , async ( ) => {
1400+ let conf : ClientConfig = {
1401+ baseURLs : [ baseURL ] ,
1402+ cacheCapacity : 1000
1403+ }
1404+ let client = SchemaRegistryClient . newClient ( conf )
1405+ let serConfig : AvroSerializerConfig = {
1406+ useLatestVersion : true ,
1407+ ruleConfig : {
1408+ secret : 'mysecret'
1409+ }
1410+ }
1411+ let ser = new AvroSerializer ( client , SerdeType . VALUE , serConfig )
1412+ let dekClient = fieldEncryptionExecutor . client !
1413+
1414+ let encRule : Rule = {
1415+ name : 'test-encrypt' ,
1416+ kind : 'TRANSFORM' ,
1417+ mode : RuleMode . WRITEREAD ,
1418+ type : 'ENCRYPT' ,
1419+ tags : [ 'PII' ] ,
1420+ params : {
1421+ 'encrypt.kek.name' : 'kek1' ,
1422+ 'encrypt.kms.type' : 'local-kms' ,
1423+ 'encrypt.kms.key.id' : 'mykey' ,
1424+ } ,
1425+ onFailure : 'ERROR,NONE'
1426+ }
1427+ let ruleSet : RuleSet = {
1428+ domainRules : [ encRule ]
1429+ }
1430+
1431+ let info : SchemaInfo = {
1432+ schemaType : 'AVRO' ,
1433+ schema : complexNestedSchema ,
1434+ ruleSet
1435+ }
1436+
1437+ await client . register ( subject , info , false )
1438+
1439+ let obj = {
1440+ emails : [ {
1441+ email : "john@acme.com" ,
1442+ } ] ,
1443+ }
1444+ let bytes = await ser . serialize ( topic , obj )
1445+
1446+ let deserConfig : AvroDeserializerConfig = {
1447+ ruleConfig : {
1448+ secret : 'mysecret'
1449+ }
1450+ }
1451+ let deser = new AvroDeserializer ( client , SerdeType . VALUE , deserConfig )
1452+ fieldEncryptionExecutor . client = dekClient
1453+ let obj2 = await deser . deserialize ( topic , bytes )
1454+ expect ( obj2 . emails [ 0 ] . email ) . toEqual ( 'john@acme.com' ) ;
1455+ } )
13611456 it ( 'jsonata fully compatible' , async ( ) => {
13621457 let rule1To2 = "$merge([$sift($, function($v, $k) {$k != 'size'}), {'height': $.'size'}])"
13631458 let rule2To1 = "$merge([$sift($, function($v, $k) {$k != 'height'}), {'size': $.'height'}])"
0 commit comments