コード例 #1
0
        public void DecryptLicenses_ReturnsNoLicenses_WhenTheEncryptedLicensesStringIsAnInvalidValue()
        {
            // Arrange
            const string encryptedLicenses = "invalid encrypted value";

            // Act
            var decryptedLicenses = FeatureLicenseHelper.DecryptLicenses(encryptedLicenses);

            // Assert
            Assert.AreEqual(0, decryptedLicenses.Length);
        }
コード例 #2
0
        public void DecryptLicenses_ReturnsNoLicenses_WhenTheEncryptedLicensesStringIsNull()
        {
            // Arrange
            string encryptedLicenses = null;

            // Act
            var decryptedLicenses = FeatureLicenseHelper.DecryptLicenses(encryptedLicenses);

            // Assert
            Assert.AreEqual(0, decryptedLicenses.Length);
        }
コード例 #3
0
        public async Task <IEnumerable <ApplicationSetting> > GetSettingsAsync(bool returnNonRestrictedOnly)
        {
            var prm = new DynamicParameters();

            prm.Add("@returnNonRestrictedOnly", returnNonRestrictedOnly);
            var settings = (await _connectionWrapper.QueryAsync <ApplicationSetting>("GetApplicationSettings", prm, commandType: CommandType.StoredProcedure)).ToList();

            // decrypt the license information
            bool workflowFeatureEnabled = false;
            var  licenseInfo            = settings.FirstOrDefault(s => s.Key == ServiceConstants.LicenseInfoApplicationSettingKey);

            if (licenseInfo != null)
            {
                var licenses        = FeatureLicenseHelper.DecryptLicenses(licenseInfo.Value);
                var workflowLicense = licenses?.FirstOrDefault(f => f.GetFeatureType() == FeatureTypes.Workflow);
                if (workflowLicense?.GetStatus() == FeatureLicenseStatus.Active)
                {
                    workflowFeatureEnabled = true;
                }
                settings.Remove(licenseInfo);
            }

            var tenantInfo = await GetTenantInfo();

            settings.AddRange(new[]
            {
                new ApplicationSetting
                {
                    Key   = ServiceConstants.ForgotPasswordUrlConfigKey,
                    Value = ServiceConstants.ForgotPasswordUrl
                },
                new ApplicationSetting
                {
                    Key   = ServiceConstants.WorkflowFeatureKey,
                    Value = workflowFeatureEnabled.ToString()
                },
                new ApplicationSetting
                {
                    Key   = ServiceConstants.TenantIdKey,
                    Value = tenantInfo?.TenantId
                },
                new ApplicationSetting
                {
                    Key   = ServiceConstants.PackageNameKey,
                    Value = tenantInfo?.PackageName
                }
            });

            return(settings);
        }
コード例 #4
0
        public void DecryptLicenses_ReturnsNoLicenses_WhenLicensesAreNotAnArrayOfFeatureInformationObjects()
        {
            // Arrange
            var license           = new[] { "this is not an array of FeatureInformation objects" };
            var xml               = SerializationHelper.ToXml(license);
            var encryptedXml      = SystemEncryptions.Encrypt(xml);
            var encryptedLicenses = encryptedXml;

            // Act
            var decryptedLicenses = FeatureLicenseHelper.DecryptLicenses(encryptedLicenses);

            // Assert
            Assert.AreEqual(0, decryptedLicenses.Length);
        }
コード例 #5
0
        public void DecryptLicenses_ReturnsLicenseTypeNone_WhenTheEncryptedLicenseHasAnInvalidFeatureName()
        {
            // Arrange
            var license           = new[] { new FeatureInformation("invalid feature name", DateTime.MaxValue) };
            var xml               = SerializationHelper.ToXml(license);
            var encryptedXml      = SystemEncryptions.Encrypt(xml);
            var encryptedLicenses = encryptedXml;

            // Act
            var decryptedLicenses = FeatureLicenseHelper.DecryptLicenses(encryptedLicenses);

            // Assert
            Assert.AreEqual(1, decryptedLicenses.Length);
            var featureType = decryptedLicenses.Single().GetFeatureType();

            Assert.AreEqual(FeatureTypes.None, featureType);
        }
コード例 #6
0
        public void DecryptLicenses_DecryptsAllLicensesSuccessfully()
        {
            // Arrange
            var expirationDate = DateTime.MaxValue;
            var allFeatures    = FeatureInformation.Features.Select(p => new FeatureInformation(p.Key, expirationDate)).ToArray();
            var xml            = SerializationHelper.ToXml(allFeatures);
            var encryptedXml   = SystemEncryptions.Encrypt(xml);

            // Act
            var decryptedLicenses = FeatureLicenseHelper.DecryptLicenses(encryptedXml);

            // Assert
            Assert.AreEqual(allFeatures.Length, decryptedLicenses.Length);
            foreach (var feature in allFeatures)
            {
                var decryptedLicense = decryptedLicenses.Single(l => l.FeatureName == feature.FeatureName && l.ExpirationDate == feature.ExpirationDate);
                Assert.IsNotNull(decryptedLicense);
            }
        }