public void Test_Encrypt2_String() { var key = "!mysecretkey#9^5usdk39d&dlf)03sL"; var config = new ClientConfiguration(TestConfiguration.GetConfiguration()); config.EnableFieldEncryption(new AesCryptoProvider(new InsecureKeyStore( new KeyValuePair <string, string>("mypublickey", key), new KeyValuePair <string, string>("myauthsecret", "myauthpassword"))) { PublicKeyName = "mypublickey", PrivateKeyName = "myauthsecret" }); using (var cluster = new Cluster(config)) { cluster.Authenticate("Administrator", "password"); var bucket = cluster.OpenBucket(); var poco = new Poco2 { Message = "The old grey goose jumped over the wrickety gate." }; var result = bucket.Upsert("thepoco2_", poco); Assert.True(result.Success); var get = bucket.Get <Poco2>("thepoco2"); Assert.True(get.Success); } }
public void When_CryptoProviders_Are_Null_Throw_ArgumentException() { var settings = new JsonSerializerSettings { ContractResolver = new FieldEncryptorContractResolver(null) }; var pocoPlain = new Poco2 { Foo = new List <int> { 3, 4, 5 } }; Assert.Throws <ArgumentException>(() => JsonConvert.SerializeObject(pocoPlain, settings)); }
public void Test_Null_Encryption_RoundTrip() { var settings = GetSettings(); var pocoPlain = new Poco2 { Foo = null }; var json = JsonConvert.SerializeObject(pocoPlain, settings); Assert.Contains("__encrypt", json); var poco = JsonConvert.DeserializeObject <Poco2>(json, settings); Assert.Null(poco.Foo); }
public void Test_List_Encryption_RoundTrip() { var settings = GetSettings(); var pocoPlain = new Poco2 { Foo = new List <int> { 3, 4, 5 } }; var json = JsonConvert.SerializeObject(pocoPlain, settings); var poco = JsonConvert.DeserializeObject <Poco2>(json, settings); Assert.Equal(new List <int> { 3, 4, 5 }, poco.Foo); }
public void When_No_CryptoProviders_Configured_Throw_ArgumentException() { var cryptoProviders = new Dictionary <string, ICryptoProvider> { //uh oh }; var settings = new JsonSerializerSettings { ContractResolver = new FieldEncryptorContractResolver(cryptoProviders) }; var pocoPlain = new Poco2 { Foo = new List <int> { 3, 4, 5 } }; Assert.Throws <ArgumentException>(() => { var result = JsonConvert.SerializeObject(pocoPlain, settings); return(result); }); }
public void CqlClient_TwoInstancesBasedOnSameSession() { // Setup MappingConfiguration config1 = new MappingConfiguration(); config1.MapperFactory.PocoDataFactory.AddDefinitionDefault(typeof(Poco1), () => LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof(Poco1))); var table1 = new Table <Poco1>(_session, config1); table1.Create(); string cqlSelectAll1 = "SELECT * from " + table1.Name; MappingConfiguration config2 = new MappingConfiguration(); config2.MapperFactory.PocoDataFactory.AddDefinitionDefault(typeof(Poco2), () => LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof(Poco2))); var table2 = new Table <Poco2>(_session, config2); table2.Create(); string cqlSelectAll2 = "SELECT * from " + table2.Name; // Now re-instantiate the cqlClient, but with mapping rule that resolves the missing key issue var cqlClient1 = new Mapper(_session, new MappingConfiguration().Define(new Poco1Mapping())); var cqlClient2 = new Mapper(_session, new MappingConfiguration().Define(new Poco2Mapping())); // insert new record into two separate tables Poco1 poco1 = new Poco1(); poco1.SomeString1 += "1"; cqlClient1.Insert(poco1); Poco2 poco2 = new Poco2(); poco2.SomeString2 += "1"; cqlClient2.Insert(poco2); // Select Values from each table List <Poco1> poco1s = cqlClient1.Fetch <Poco1>(cqlSelectAll1).ToList(); Assert.AreEqual(1, poco1s.Count); Assert.AreEqual(poco1.SomeString1, poco1s[0].SomeString1); Assert.AreEqual(poco1.SomeDouble1, poco1s[0].SomeDouble1); List <Poco2> poco2s = cqlClient2.Fetch <Poco2>(cqlSelectAll2).ToList(); Assert.AreEqual(1, poco2s.Count); Assert.AreEqual(poco2.SomeString2, poco2s[0].SomeString2); Assert.AreEqual(poco2.SomeDouble2, poco2s[0].SomeDouble2); // Try that again poco1s.Clear(); Assert.AreEqual(0, poco1s.Count); poco1s = cqlClient1.Fetch <Poco1>(cqlSelectAll1).ToList(); Assert.AreEqual(1, poco1s.Count); Assert.AreEqual(poco1.SomeString1, poco1s[0].SomeString1); Assert.AreEqual(poco1.SomeDouble1, poco1s[0].SomeDouble1); poco2s.Clear(); Assert.AreEqual(0, poco2s.Count); poco2s = cqlClient1.Fetch <Poco2>(cqlSelectAll2).ToList(); Assert.AreEqual(1, poco2s.Count); Assert.AreEqual(poco2.SomeString2, poco2s[0].SomeString2); Assert.AreEqual(poco2.SomeDouble2, poco2s[0].SomeDouble2); }
public void CqlClient_TwoInstancesBasedOnSameSession() { // Setup MappingConfiguration config1 = new MappingConfiguration(); config1.MapperFactory.PocoDataFactory.AddDefinitionDefault(typeof(Poco1), () => LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof(Poco1))); var table1 = new Table <Poco1>(Session, config1); string cqlSelectAll1 = "SELECT * from " + table1.Name; MappingConfiguration config2 = new MappingConfiguration(); config2.MapperFactory.PocoDataFactory.AddDefinitionDefault(typeof(Poco2), () => LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof(Poco2))); var table2 = new Table <Poco2>(Session, config2); string cqlSelectAll2 = "SELECT * from " + table2.Name; // Now re-instantiate the cqlClient, but with mapping rule that resolves the missing key issue var cqlClient1 = new Mapper(Session, new MappingConfiguration().Define(new Poco1Mapping())); var cqlClient2 = new Mapper(Session, new MappingConfiguration().Define(new Poco2Mapping())); // insert new record into two separate tables Poco1 poco1 = new Poco1(); poco1.SomeString1 += "1"; cqlClient1.Insert(poco1); VerifyBoundStatement( "INSERT INTO poco1 (SomeDouble1, somestring1) VALUES (?, ?)", 1, poco1.SomeDouble1, poco1.SomeString1); Poco2 poco2 = new Poco2(); poco2.SomeString2 += "1"; cqlClient2.Insert(poco2); VerifyBoundStatement( "INSERT INTO poco2 (SomeDouble2, somestring2) VALUES (?, ?)", 1, poco2.SomeDouble2, poco2.SomeString2); // Select Values from each table TestCluster.PrimeFluent( b => b.WhenQuery("SELECT * from poco1") .ThenRowsSuccess(new[] { "SomeDouble1", "somestring1" }, r => r.WithRow(poco1.SomeDouble1, poco1.SomeString1))); List <Poco1> poco1s = cqlClient1.Fetch <Poco1>(cqlSelectAll1).ToList(); Assert.AreEqual(1, poco1s.Count); Assert.AreEqual(poco1.SomeString1, poco1s[0].SomeString1); Assert.AreEqual(poco1.SomeDouble1, poco1s[0].SomeDouble1); TestCluster.PrimeFluent( b => b.WhenQuery("SELECT * from poco2") .ThenRowsSuccess(new[] { "SomeDouble2", "somestring2" }, r => r.WithRow(poco2.SomeDouble2, poco2.SomeString2))); List <Poco2> poco2s = cqlClient2.Fetch <Poco2>(cqlSelectAll2).ToList(); Assert.AreEqual(1, poco2s.Count); Assert.AreEqual(poco2.SomeString2, poco2s[0].SomeString2); Assert.AreEqual(poco2.SomeDouble2, poco2s[0].SomeDouble2); // Try that again poco1s.Clear(); Assert.AreEqual(0, poco1s.Count); poco1s = cqlClient1.Fetch <Poco1>(cqlSelectAll1).ToList(); Assert.AreEqual(1, poco1s.Count); Assert.AreEqual(poco1.SomeString1, poco1s[0].SomeString1); Assert.AreEqual(poco1.SomeDouble1, poco1s[0].SomeDouble1); poco2s.Clear(); Assert.AreEqual(0, poco2s.Count); poco2s = cqlClient1.Fetch <Poco2>(cqlSelectAll2).ToList(); Assert.AreEqual(1, poco2s.Count); Assert.AreEqual(poco2.SomeString2, poco2s[0].SomeString2); Assert.AreEqual(poco2.SomeDouble2, poco2s[0].SomeDouble2); }