Example #1
0
            protected override void Test(IOrganizationService service)
            {
                service = new OrganizationServiceBuilder(service)
                          .Build();

                var plugin = new Sample.FieldEncryptionPlugin(null, null);

                plugin.Container.Implement <ICache>().Using <Fakes.FakeCacheProvider>().WithOverwrite();
                plugin.Container.Implement <ISecretProviderFactory>().Using <Fakes.FakeSecretProviderFactory <Fakes.FakeSecretProvider> >().WithOverwrite();


                var target = new Contact()
                {
                    Id         = ExistingIds.Contact.EntityId,
                    Department = TestData.DecryptedValue
                };


                var executionContext = new PluginExecutionContextBuilder()
                                       .WithRegisteredEvent(20, "Update", Contact.EntityLogicalName)
                                       .WithInputParameter("Target", target)
                                       .Build();

                var serviceProvider = new ServiceProviderBuilder(
                    service,
                    executionContext,
                    new DebugLogger()).Build();

                plugin.Execute(serviceProvider);


                var contextTarget = executionContext.InputParameters["Target"] as Contact;

                Assert.AreEqual(TestData.EncryptedValue, contextTarget.Department);
            }
            protected override void Test(IOrganizationService service)
            {
                service = new OrganizationServiceBuilder(service)
                          .Build();

                var plugin = new Sample.FieldEncryptionPlugin(null, null);

                plugin.Container.Implement <ICache>().Using <Fakes.FakeCacheProvider>().WithOverwrite();
                plugin.Container.Implement <ISecretProviderFactory>().Using <Fakes.FakeSecretProviderFactory <Fakes.FakeSecretProvider> >().WithOverwrite();

                var testQry = new QueryExpressionBuilder <Contact>()
                              .Select("department")
                              .WhereAll(e => e
                                        .IsActive()
                                        .WhereAll(e1 => e1
                                                  .Attribute("fullname").Is(ConditionOperator.Like, "# " + TestData.DecryptedValue + "%")))
                              .Build();


                var executionContext = new PluginExecutionContextBuilder()
                                       .WithRegisteredEvent(20, "RetrieveMultiple", Contact.EntityLogicalName)
                                       .WithInputParameter("Query", testQry)
                                       .Build();

                var serviceProvider = new ServiceProviderBuilder(
                    service,
                    executionContext,
                    new DebugLogger()).Build();

                plugin.Execute(serviceProvider);

                var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

                // get query and verify that it is modified as expected.
                var outQuery = context.InputParameters["Query"] as QueryExpression;

                var criteria = outQuery.Criteria;

                Assert.AreEqual(LogicalOperator.Or, criteria.FilterOperator);
                Assert.AreEqual(0, criteria.Conditions.Count);
                Assert.AreEqual(1, criteria.Filters.Count);

                // check sub filter
                criteria = criteria.Filters[0];

                Assert.AreEqual(LogicalOperator.And, criteria.FilterOperator);
                Assert.AreEqual(2, criteria.Conditions.Count);
                Assert.AreEqual(0, criteria.Filters.Count);

                Assert.AreEqual("department", criteria.Conditions[0].AttributeName);
                Assert.AreEqual(TestData.EncryptedValue, criteria.Conditions[0].Values[0]);

                Assert.AreEqual("statecode", criteria.Conditions[1].AttributeName);
                Assert.AreEqual(0, criteria.Conditions[1].Values[0]);
            }
Example #3
0
            protected override void Test(IOrganizationService service)
            {
                service = new OrganizationServiceBuilder(service)
                          .Build();

                var plugin = new Sample.FieldEncryptionPlugin(null, null);

                plugin.Container.Implement <ICache>().Using <Fakes.FakeCacheProvider>().WithOverwrite();
                plugin.Container.Implement <ISecretProviderFactory>().Using <Fakes.FakeSecretProviderFactory <Fakes.FakeSecretProvider> >().WithOverwrite();


                plugin.Container.Implement <ISecretProviderFactory>().Using <Fakes.FakeSecretProviderFactory <Fakes.FakeSecretProvider> >().WithOverwrite();


                var target = new Contact()
                {
                    Id         = ExistingIds.Contact.EntityId,
                    Department = TestData.EncryptedValue
                };

                var maskingInstructions = new Dictionary <string, EncryptedFieldService.MaskingInstruction>();

                maskingInstructions.Add("department", EncryptedFieldService.MaskingInstruction.Unmask);


                var executionContext = new PluginExecutionContextBuilder()
                                       .WithRegisteredEvent(40, "Retrieve", Contact.EntityLogicalName)
                                       .WithInputParameter("Target", target.ToEntityReference())
                                       .WithInputParameter("ColumnSet", new ColumnSet("display"))
                                       .WithOutputParameter("Entity", target)
                                       .WithSharedVariable("CCLLC.EncryptedFieldService.DecryptColumns", maskingInstructions)
                                       .Build();

                var serviceProvider = new ServiceProviderBuilder(
                    service,
                    executionContext,
                    new DebugLogger()).Build();

                plugin.Execute(serviceProvider);


                var contextTarget = executionContext.OutputParameters["Entity"] as Contact;

                Assert.AreEqual(TestData.DecryptedValue, contextTarget.Department);
            }
Example #4
0
            protected override void Test(IOrganizationService service)
            {
                service = new OrganizationServiceBuilder(service)
                          .Build();

                var plugin = new Sample.FieldEncryptionPlugin(null, null);

                plugin.Container.Implement <ICache>().Using <Fakes.FakeCacheProvider>().WithOverwrite();
                plugin.Container.Implement <ISecretProviderFactory>().Using <Fakes.FakeSecretProviderFactory <Fakes.FakeSecretProvider> >().WithOverwrite();


                var target = new Contact()
                {
                    Id         = ExistingIds.Contact.EntityId,
                    Department = TestData.EncryptedValue
                };

                var executionContext = new PluginExecutionContextBuilder()
                                       .WithRegisteredEvent(20, "Retrieve", Contact.EntityLogicalName)
                                       .WithInputParameter("Target", target.ToEntityReference())
                                       .WithInputParameter("ColumnSet", new ColumnSet("department", "telephone1"))
                                       .WithOutputParameter("Entity", target)
                                       .Build();

                var serviceProvider = new ServiceProviderBuilder(
                    service,
                    executionContext,
                    new DebugLogger()).Build();

                plugin.Execute(serviceProvider);

                var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

                var columns = context.InputParameters["ColumnSet"] as ColumnSet;

                Assert.AreEqual(1, columns.Columns.Count);
                Assert.IsTrue(columns.Columns.Contains("department"));
            }