Example #1
0
        public void ToString_should_return_expected_result()
        {
            var guid      = new Guid("00112233445566778899aabbccddeeff");
            var guidBytes = GuidConverter.ToBytes(guid, GuidRepresentation.Standard);
            var binary    = new BsonBinaryData(guidBytes, BsonBinarySubType.UuidStandard);

            var extraOptions = new Dictionary <string, object>()
            {
                { "mongocryptdURI", "testURI" },
            };
            var kmsProviders = new Dictionary <string, IReadOnlyDictionary <string, object> >()
            {
                { "provider1", new Dictionary <string, object>()
                  {
                      { "string", "test" }
                  } },
                { "provider2", new Dictionary <string, object>()
                  {
                      { "binary", binary.Bytes }
                  } }
            };
            var schemaMap = new Dictionary <string, BsonDocument>()
            {
                { "coll1", new BsonDocument("string", "test") },
                { "coll2", new BsonDocument("binary", binary) },
            };
            var tlsOptions = new Dictionary <string, SslSettings>
            {
                { "local", new SslSettings {
                      ClientCertificates = new [] { Mock.Of <X509Certificate2>() }
                  } }
            };
            var encryptedFieldsMap = new Dictionary <string, BsonDocument>
            {
                {
                    "db.test",
                    BsonDocument.Parse("{ dummy : 'doc' }")
                }
            };

            var subject = new AutoEncryptionOptions(
                keyVaultNamespace: __keyVaultNamespace,
                kmsProviders: kmsProviders,
                bypassAutoEncryption: true,
                extraOptions: extraOptions,
                schemaMap: schemaMap,
                tlsOptions: tlsOptions,
                encryptedFieldsMap: encryptedFieldsMap);

            var result = subject.ToString();

            result.Should().Be("{ BypassAutoEncryption : True, KmsProviders : { \"provider1\" : { \"string\" : \"test\" }, \"provider2\" : { \"binary\" : { \"_t\" : \"System.Byte[]\", \"_v\" : new BinData(0, \"ABEiM0RVZneImaq7zN3u/w==\") } } }, KeyVaultNamespace : \"db.coll\", ExtraOptions : { \"mongocryptdURI\" : \"testURI\" }, SchemaMap : { \"coll1\" : { \"string\" : \"test\" }, \"coll2\" : { \"binary\" : UUID(\"00112233-4455-6677-8899-aabbccddeeff\") } }, TlsOptions: [{ \"local\" : \"<hidden>\" }], EncryptedFieldsMap : { \"db.test\" : { \"dummy\" : \"doc\" } } }");
        }
Example #2
0
        public void ToString_should_return_expected_result()
        {
            var guid      = new Guid("00112233445566778899aabbccddeeff");
            var guidBytes = GuidConverter.ToBytes(guid, GuidRepresentation.Standard);
            var binary    = new BsonBinaryData(guidBytes, BsonBinarySubType.UuidStandard);

            var extraOptions = new Dictionary <string, object>()
            {
                { "mongocryptdURI", "testURI" },
            };
            var kmsProviders = new Dictionary <string, IReadOnlyDictionary <string, object> >()
            {
                { "provider1", new Dictionary <string, object>()
                  {
                      { "string", "test" }
                  } },
                { "provider2", new Dictionary <string, object>()
                  {
                      { "binary", binary.Bytes }
                  } }
            };
            var schemaMap = new Dictionary <string, BsonDocument>()
            {
                { "coll1", new BsonDocument("string", "test") },
                { "coll2", new BsonDocument("binary", binary) },
            };

            var subject = new AutoEncryptionOptions(
                keyVaultNamespace: CollectionNamespace.FromFullName("db.coll"),
                kmsProviders: kmsProviders,
                bypassAutoEncryption: true,
                extraOptions: extraOptions,
                schemaMap: schemaMap);

            var result = subject.ToString();

            result.Should().Be("{ BypassAutoEncryption : True, KmsProviders : { \"provider1\" : { \"string\" : \"test\" }, \"provider2\" : { \"binary\" : { \"_t\" : \"System.Byte[]\", \"_v\" : new BinData(0, \"ABEiM0RVZneImaq7zN3u/w==\") } } }, KeyVaultNamespace : \"db.coll\", ExtraOptions : { \"mongocryptdURI\" : \"testURI\" }, SchemaMap : { \"coll1\" : { \"string\" : \"test\" }, \"coll2\" : { \"binary\" : UUID(\"00112233-4455-6677-8899-aabbccddeeff\") } } }");
        }