Exemple #1
0
        public void Should_be_able_to_encrypt_and_decrypt()
        {
            var keyPair = Helpers.GenerateKeyPairXml();

            byte[] encrypted = domainLicense.SerializeAndEncrypt(keyPair);

            var encryptedDomainLicense  = new DomainLicense(encrypted, keyPair);
            var serializedDomainLicense = encryptedDomainLicense.SerializeUnencrypted();

            serializedDomainLicense.ShouldEqual(domainLicense.SerializeUnencrypted());
        }
            public WhenLocalCacheContainsLicenseInformationTests()
            {
                featureOne   = Guid.NewGuid();
                featureTwo   = Guid.NewGuid();
                featureThree = Guid.NewGuid();
                featureFour  = Guid.NewGuid();
                featureFive  = Guid.NewGuid();
                featureSix   = Guid.NewGuid();
                featureSeven = Guid.NewGuid();

                var httpClient = Substitute.For <IHttpClient>();

                string keyPair = Helpers.GenerateKeyPairXml();

                // featureOne and featureThree belong to an expired license
                var expiredDomainLicense = new DomainLicense(
                    "expired.com",
                    "John Doe",
                    DateTime.UtcNow.AddYears(-1),
                    DateTime.UtcNow.AddHours(24).AddYears(-1),
                    new List <Guid> {
                    featureOne,
                    featureThree
                }
                    );

                var issued  = DateTime.UtcNow;
                var expires = DateTime.UtcNow.AddHours(24);
                // featureTwo and featureFive have already been verified
                var cachedDomainLicense = new DomainLicense(
                    "domain.com",
                    "John Doe",
                    issued,
                    expires,
                    new List <Guid> {
                    featureTwo,
                    featureFive
                }
                    );

                // featureSix and featureSeven are Pending, but only featureSix will be enabled
                var keyHubDomainLicense = new DomainLicense(
                    "domain.com",
                    "John Doe",
                    issued,
                    expires,
                    new List <Guid> {
                    featureTwo,
                    featureFour,   // Rejected in the past is now enabled
                    featureFive,
                    featureSix     // Pending new feature
                }
                    );

                httpClient.Send(Arg.Any <HttpRequest>()).Returns(new HttpResponse {
                    Content = Helpers.GenerateValidXmlResponseFromKeyHub(keyPair, new List <DomainLicense> {
                        keyHubDomainLicense
                    })
                });

                licenseStore = Substitute.For <ILicenseStore>();
                licenseStore.GetLicenses().Returns(new List <byte[]> {
                    expiredDomainLicense.SerializeAndEncrypt(keyPair),
                    cachedDomainLicense.SerializeAndEncrypt(keyPair)
                });

                var featureStates = new Dictionary <string, Dictionary <Guid, FeatureState> > {
                    {
                        "expired.com",
                        new Dictionary <Guid, FeatureState> {
                            { featureOne, FeatureState.Enabled },
                            { featureThree, FeatureState.Enabled }
                        }
                    },
                    {
                        "domain.com",
                        new Dictionary <Guid, FeatureState> {
                            { featureTwo, FeatureState.Enabled },
                            { featureFour, FeatureState.Rejected },
                            { featureFive, FeatureState.Enabled },
                            { featureSix, FeatureState.Pending },
                            { featureSeven, FeatureState.Pending }
                        }
                    }
                };

                var pendingFeatures = new Dictionary <string, List <Guid> > {
                    {
                        "domain.com",
                        new List <Guid> {
                            featureSix,
                            featureSeven
                        }
                    }
                };

                verifyAction           = new VerifyAction(httpClient, keyPair, Guid.NewGuid(), licenseStore, featureStates, pendingFeatures);
                verifyAction.Finished += verifyAction_Finished;
            }