|
| 1 | +import { BSON } from 'mongodb'; |
1 | 2 | import { |
2 | 3 | AnyArray, |
3 | 4 | Schema, |
@@ -74,3 +75,39 @@ function defaultOptions() { |
74 | 75 | expectType<Record<string, any>>(new Schema.Types.Subdocument('none').defaultOptions); |
75 | 76 | expectType<Record<string, any>>(new Schema.Types.UUID('none').defaultOptions); |
76 | 77 | } |
| 78 | + |
| 79 | +function encrypt() { |
| 80 | + const keyId = new BSON.UUID(); |
| 81 | + |
| 82 | + new SchemaTypeOptions<string>()['encrypt'] = { keyId, algorithm: 'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic' }; |
| 83 | + new SchemaTypeOptions<string>()['encrypt'] = { keyId, algorithm: 'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic' }; |
| 84 | + new SchemaTypeOptions<string>()['encrypt'] = { keyId, algorithm: 'AEAD_AES_256_CBC_HMAC_SHA_512-Random' }; |
| 85 | + new SchemaTypeOptions<string>()['encrypt'] = { keyId, algorithm: 'Indexed' }; |
| 86 | + new SchemaTypeOptions<string>()['encrypt'] = { keyId, algorithm: 'Unindexed' }; |
| 87 | + new SchemaTypeOptions<string>()['encrypt'] = { keyId, algorithm: 'Range' }; |
| 88 | + new SchemaTypeOptions<string>()['encrypt'] = { keyId, algorithm: undefined }; |
| 89 | + |
| 90 | + // qe + valid queries |
| 91 | + new SchemaTypeOptions<string>()['encrypt'] = { keyId, queries: 'equality' }; |
| 92 | + new SchemaTypeOptions<string>()['encrypt'] = { keyId, queries: 'range' }; |
| 93 | + new SchemaTypeOptions<string>()['encrypt'] = { keyId, queries: undefined }; |
| 94 | + |
| 95 | + // empty object |
| 96 | + expectError<SchemaTypeOptions<string>['encrypt']>({}); |
| 97 | + |
| 98 | + // invalid keyId |
| 99 | + expectError<SchemaTypeOptions<string>['encrypt']>({ keyId: 'fakeId' }); |
| 100 | + |
| 101 | + // missing keyId |
| 102 | + expectError<SchemaTypeOptions<string>['encrypt']>({ queries: 'equality' }); |
| 103 | + expectError<SchemaTypeOptions<string>['encrypt']>({ algorithm: 'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic' }); |
| 104 | + |
| 105 | + // invalid algorithm |
| 106 | + expectError<SchemaTypeOptions<string>['encrypt']>({ keyId, algorithm: 'SHA_FAKE_ALG' }); |
| 107 | + |
| 108 | + // invalid queries |
| 109 | + expectError<SchemaTypeOptions<string>['encrypt']>({ keyId, queries: 'fakeQueryOption' }); |
| 110 | + |
| 111 | + // invalid input option |
| 112 | + expectError<SchemaTypeOptions<string>['encrypt']>({ keyId, invalidKey: 'fakeKeyOption' }); |
| 113 | +} |
0 commit comments