Ejemplo n.º 1
0
        public void Test_Offline_License_Success()
        {
            var clock = new OffsetClock("2017-04-25", "2017-04-25");
            var mgr   = new LicenseManagerSingleton(ImazenPublicKeys.Test, clock)
            {
                Cache = new StringCacheMem()
            };
            var conf = new Config(new ResizerSection(
                                      @"<resizer><licenses>
      <maphost from='localhost' to='acme.com' />
      <license>" + LicenseStrings.Offlinev4DomainAcmeComCreative + "</license></licenses></resizer>"));

            conf.Plugins.LicenseScope = LicenseAccess.Local;
            conf.Plugins.Install(new LicensedPlugin(mgr, clock, "R4Creative"));

            Assert.Equal(0, mgr.WaitForTasks());
            Assert.Empty(mgr.GetIssues());

            Assert.NotNull(mgr.GetAllLicenses().First());

            var result = new Computation(conf, ImazenPublicKeys.Test, mgr, mgr, clock, true);

            Assert.True(result.LicensedForRequestUrl(new Uri("http://acme.com")));
            Assert.True(result.LicensedForRequestUrl(new Uri("http://subdomain.acme.com")));
            Assert.True(result.LicensedForRequestUrl(new Uri("http://localhost")));
            Assert.False(result.LicensedForRequestUrl(new Uri("http://other.com")));
            Assert.Equal(0, mgr.WaitForTasks());
            Assert.Empty(mgr.GetIssues());
            Assert.NotNull(conf.GetDiagnosticsPage());
            Assert.NotNull(conf.GetLicensesPage());
        }
Ejemplo n.º 2
0
        public void Test_Offline_License_Failure()
        {
            var clock = new OffsetClock("2017-04-25", "2017-04-25");
            var mgr   = new LicenseManagerSingleton(ImazenPublicKeys.Test, clock)
            {
                Cache = new StringCacheMem()
            };
            var conf = new Config();

            conf.Plugins.LicenseScope = LicenseAccess.Local;
            conf.Plugins.Install(new LicensedPlugin(mgr, clock, "R4Creative"));

            Assert.Empty(mgr.GetIssues());
            Assert.Null(mgr.GetAllLicenses().FirstOrDefault());

            var result = new Computation(conf, ImazenPublicKeys.Test, mgr, mgr, clock, true);

            Assert.False(result.LicensedForRequestUrl(new Uri("http://acme.com")));
            conf.Plugins.AddLicense(LicenseStrings.Offlinev4DomainAcmeComCreative);

            Assert.NotNull(mgr.GetAllLicenses().First());

            result = new Computation(conf, ImazenPublicKeys.Test, mgr, mgr, clock, true);
            Assert.True(result.LicensedForRequestUrl(new Uri("http://acme.com")));

            Assert.Empty(mgr.GetIssues());
            Assert.NotNull(conf.GetDiagnosticsPage());
            Assert.NotNull(conf.GetLicensesPage());
        }
Ejemplo n.º 3
0
        public void Test_Remote_License_Success()
        {
            if (Environment.GetEnvironmentVariable("APPVEYOR") == "True")
            {
                return;
            }
            var clock = new OffsetClock("2017-04-25", "2017-04-25");
            var mgr   = new LicenseManagerSingleton(ImazenPublicKeys.Test, clock)
            {
                Cache = new StringCacheMem()
            };
            Uri invokedUri  = null;
            var httpHandler = MockHttpHelpers.MockRemoteLicense(mgr, HttpStatusCode.OK, LicenseStrings.EliteSubscriptionRemote,
                                                                (r, c) => { invokedUri = r.RequestUri; });
            var conf = new Config();

            try {
                conf.Plugins.LicenseScope = LicenseAccess.Local;
                conf.Plugins.Install(new LicensedPlugin(mgr, clock, "R_Elite"));
                conf.Plugins.AddLicense(LicenseStrings.EliteSubscriptionPlaceholder);

                Assert.Equal(1, mgr.GetAllLicenses().Count());
                Assert.True(mgr.GetAllLicenses().First().IsRemote);
                mgr.Heartbeat();

                mgr.WaitForTasks();
                Assert.Empty(mgr.GetIssues());

                Mock.Verify(httpHandler);
                Assert.StartsWith(
                    "https://s3-us-west-2.amazonaws.com/licenses.imazen.net/v1/licenses/latest/",
                    invokedUri.ToString());


                Assert.NotNull(mgr.GetAllLicenses().First().FetchedLicense());

                var result = new Computation(conf, ImazenPublicKeys.Test, mgr, mgr, clock, true);

                Assert.True(result.LicensedForRequestUrl(new Uri("http://anydomain")));
                Assert.Equal(0, mgr.WaitForTasks());
                Assert.Empty(mgr.GetIssues());
                Assert.NotNull(conf.GetDiagnosticsPage());
                Assert.NotNull(conf.GetLicensesPage());
            } catch {
                output.WriteLine(conf.GetDiagnosticsPage());
                throw;
            }
        }
Ejemplo n.º 4
0
        public void Test_Caching_With_Write_Delay()
        {
            if (Environment.GetEnvironmentVariable("APPVEYOR") == "True")
            {
                return;
            }

            var clock = new OffsetClock("2017-04-25", "2017-04-25");
            var cache = new StringCacheMem();

            // Populate cache
            {
                var mgr = new LicenseManagerSingleton(ImazenPublicKeys.Test, clock)
                {
                    Cache = cache
                };
                MockHttpHelpers.MockRemoteLicense(mgr, HttpStatusCode.OK, LicenseStrings.EliteSubscriptionRemote,
                                                  null);

                var conf = new Config();
                conf.Plugins.LicenseScope = LicenseAccess.Local;
                conf.Plugins.Install(new LicensedPlugin(mgr, clock, "R_Elite", "R4Elite"));
                conf.Plugins.AddLicense(LicenseStrings.EliteSubscriptionPlaceholder);

                Assert.Equal(1, mgr.WaitForTasks());

                var result = new Computation(conf, ImazenPublicKeys.Test, mgr, mgr, clock, true);
                Assert.True(result.LicensedForRequestUrl(new Uri("http://anydomain")));

                Assert.Empty(mgr.GetIssues());
                Assert.NotNull(conf.GetLicensesPage());
            }

            // Use cache
            {
                var mgr = new LicenseManagerSingleton(ImazenPublicKeys.Test, clock)
                {
                    Cache = cache
                };

                var conf = new Config();

                conf.Plugins.LicenseScope = LicenseAccess.Local;
                conf.Plugins.Install(new LicensedPlugin(mgr, clock, "R_Elite", "R4Elite"));
                conf.Plugins.AddLicense(LicenseStrings.EliteSubscriptionPlaceholder);

                mgr.Heartbeat();
                Assert.Equal(0, mgr.WaitForTasks());

                var result = new Computation(conf, ImazenPublicKeys.Test, mgr, mgr, clock, true);
                Assert.True(result.LicensedForRequestUrl(new Uri("http://anydomain")));


                Assert.NotNull(conf.GetDiagnosticsPage());
                Assert.NotNull(conf.GetLicensesPage());

                Assert.Equal(0, mgr.GetIssues().Count());

                MockHttpHelpers.MockRemoteLicenseException(mgr, WebExceptionStatus.NameResolutionFailure);

                while (!mgr.AllowFetching())
                {
                    mgr.Heartbeat();
                }

                mgr.WaitForTasks();

                result = new Computation(conf, ImazenPublicKeys.Test, mgr, mgr, clock, true);
                Assert.True(result.LicensedForRequestUrl(new Uri("http://anydomain")));
                Assert.Equal(1, mgr.GetIssues().Count());
            }
        }