public async void TestAGPL()
        {
            using (var contentRoot = new TempContentRoot()
                                     .AddResource("images/fire.jpg", "TestFiles.fire-umbrella-small.jpg"))
            {
                var clock     = new RealClock();
                var mgr       = new LicenseManagerSingleton(ImazenPublicKeys.Test, clock, new StringCacheMem());
                var licensing = new Licensing(mgr);


                using var host = await StartAsyncWithOptions(new ImageflowMiddlewareOptions ()
                {
                    Licensing = licensing,
                    MyOpenSourceProjectUrl = "https://github.com/username/project",
                    EnforcementMethod      = EnforceLicenseWith.RedDotWatermark
                }.MapPath("/", Path.Combine(contentRoot.PhysicalPath, "images")));

                // Create an HttpClient to send requests to the TestServer
                using var client = host.GetTestClient();

                using var licensedResponse = await client.GetAsync("/fire.jpg?w=1");

                licensedResponse.EnsureSuccessStatusCode();

                var page = licensing.Result.ProvidePublicLicensesPage();
                Assert.Contains("License Validation OFF", page);
                Assert.Contains("No license keys found.", page);
                Assert.DoesNotContain("You must purchase a license key or comply with the AGPLv3.", page);
                Assert.DoesNotContain("To get a license key", page);
                Assert.Contains("You are using EnforceLicenseWith.RedDotWatermark", page);

                await host.StopAsync(CancellationToken.None);
            }
        }
Example #2
0
        public void Test_License_Enforcer_Exception_Web_Config()
        {
            var clock   = new RealClock();
            var mgr     = new LicenseManagerSingleton(ImazenPublicKeys.Test, clock, new StringCacheMem());
            var request = new RequestUrlProvider();

            var conf = new Config(new ResizerSection(
                                      @"<resizer><licenses licenseError='exception' licenseScope='local'>
      <maphost from='localhost' to='acme.com' />
      <license>" + LicenseStrings.Offlinev4DomainAcmeComCreative + "</license></licenses>" +
                                      "<plugins><add name='Gradient'/></plugins></resizer>"));

            conf.Plugins.Install(new EmptyLicenseEnforcedPlugin(new LicenseEnforcer <EmptyLicenseEnforcedPlugin>(mgr, mgr, request.Get).EnableEnforcement(), "R4Creative"));

            request.Url = null;
            Assert.False(IsWatermarking(conf, mgr));
            request.Url = new Uri("http://acme.com");
            Assert.False(IsWatermarking(conf, mgr));
            request.Url = new Uri("http://subdomain.acme.com");
            Assert.False(IsWatermarking(conf, mgr));
            request.Url = new Uri("http://localhost");
            Assert.False(IsWatermarking(conf, mgr));

            request.Url = new Uri("http://other.co");
            var e = Record.Exception(() => IsWatermarking(conf, mgr));

            Assert.NotNull(e);
            Assert.IsType <LicenseException>(e);

            Assert.Empty(mgr.GetIssues());
        }
 static void Main(string[] args)
 {
     IStubClock fakeClock = new FakeClock(new DateTime(1, 1, 1, 10, 0, 0)); //time is set to 10am
     IStubClock realClock = new RealClock();                                //time is set to whatever the time now is.
     Hotel      hotel1    = new Hotel(fakeClock);                           //using fake time
     Hotel      hotel2    = new Hotel(realClock);                           //using the real time
 }
Example #4
0
        public void Test_License_Enforcer_Watermark()
        {
            var clock   = new RealClock();
            var mgr     = new LicenseManagerSingleton(ImazenPublicKeys.Test, clock, new StringCacheMem());
            var request = new RequestUrlProvider();

            var conf = new Config();

            conf.Plugins.LicenseScope = LicenseAccess.Local;
            conf.Plugins.AddLicense(LicenseStrings.Offlinev4DomainAcmeComCreative);
            conf.Plugins.LicenseError = LicenseErrorAction.Watermark;
            conf.Plugins.AddLicensedDomainMapping("localhost", "acme.com");
            conf.Plugins.Install(new Gradient());
            conf.Plugins.Install(new EmptyLicenseEnforcedPlugin(new LicenseEnforcer <EmptyLicenseEnforcedPlugin>(mgr, mgr, request.Get).EnableEnforcement(), "R4Creative"));

            request.Url = null;
            Assert.False(IsWatermarking(conf, mgr));

            request.Url = new Uri("http://acme.com");
            Assert.False(IsWatermarking(conf, mgr));

            request.Url = new Uri("http://subdomain.acme.com");
            Assert.False(IsWatermarking(conf, mgr));

            request.Url = new Uri("http://localhost");
            Assert.False(IsWatermarking(conf, mgr));

            // We should watermark unlicensed domains
            request.Url = new Uri("http://other.co");
            Assert.True(IsWatermarking(conf, mgr));
            Assert.True(IsWatermarking(conf, mgr));

            Assert.Empty(mgr.GetIssues());
        }
Example #5
0
        static void Main(string[] args)
        {
            var log      = GetProductionLogger();
            var assembly = System.Reflection.Assembly.GetExecutingAssembly();
            var fvi      = FileVersionInfo.GetVersionInfo(assembly.Location);
            var c        = new RealClock();

            log.LogInformation($"Starting PBXConnector Console Runner {fvi.FileVersion}");

            RegistryConfigurationProvider config;

            try {
                config = new RegistryConfigurationProvider(log);
            }
            catch (Exception ex) {
                log.LogError("Error starting PBXConnector Console Runner", ex);
                throw;
            }
            var ac = new ApplicationClient(
                new PBXApplicationClientConfigurationProvider(config),
                log, "CJASDBYCOKYIWBWNFPQHOBGIQPEJUBSYNEOUEKJZTOSWWCPGCRWNYGBOOUZE");
            var connector = new PBXConnection(log, config, ac, c);

            connector.Start();
        }
        public void RealClockMatchesDateTime()
        {
            IClock   clock    = new RealClock();
            DateTime dtnow    = DateTime.Now;
            DateTime clockNow = clock.Now();

            Assert.AreEqual(dtnow.ToString(), clockNow.ToString()); //Deliberately accurate only to the second.

            Assert.AreEqual(DateTime.Today, clock.Today());
        }
        public async void TestNoLicense()
        {
            using (var contentRoot = new TempContentRoot()
                                     .AddResource("images/fire.jpg", "TestFiles.fire-umbrella-small.jpg"))
            {
                var clock     = new RealClock();
                var mgr       = new LicenseManagerSingleton(ImazenPublicKeys.Test, clock, new StringCacheMem());
                var licensing = new Licensing(mgr);


                using var host = await StartAsyncWithOptions(new ImageflowMiddlewareOptions ()
                {
                    Licensing = licensing,
                    MyOpenSourceProjectUrl = null,
                    EnforcementMethod      = EnforceLicenseWith.Http402Error
                }
                                                             .SetDiagnosticsPageAccess (AccessDiagnosticsFrom.None)
                                                             .SetDiagnosticsPagePassword ("pass")
                                                             .MapPath("/", Path.Combine(contentRoot.PhysicalPath, "images")));

                // Create an HttpClient to send requests to the TestServer
                using var client = host.GetTestClient();

                using var notLicensedResponse = await client.GetAsync("/fire.jpg?w=1");

                Assert.Equal(HttpStatusCode.PaymentRequired, notLicensedResponse.StatusCode);

                using var licensePageResponse = await client.GetAsync("/imageflow.license");

                licensePageResponse.EnsureSuccessStatusCode();

                using var notAuthorizedResponse = await client.GetAsync("/imageflow.debug");

                Assert.Equal(HttpStatusCode.Unauthorized, notAuthorizedResponse.StatusCode);

                using var debugPageResponse = await client.GetAsync("/imageflow.debug?password=pass");

                debugPageResponse.EnsureSuccessStatusCode();


                var page = licensing.Result.ProvidePublicLicensesPage();
                Assert.Contains("License Validation ON", page);
                Assert.Contains("No license keys found.", page);
                Assert.Contains("You must purchase a license key or comply with the AGPLv3.", page);
                Assert.Contains("To get a license key, visit", page);
                Assert.Contains("You are using EnforceLicenseWith.Http402Error", page);

                await host.StopAsync(CancellationToken.None);
            }
        }
Example #8
0
        public async Task AcquireReleaseLockAsync()
        {
            string sentinelPath = $"{Path.GetTempPath()}\\{Guid.NewGuid():N}";

            IClock clock           = new RealClock();
            var    holdLockTimeout = TimeSpan.FromMilliseconds(250);
            var    lockTimeout     = TimeSpan.FromMilliseconds(2000);

            // Lock the sentinel file.
            var lockFileTask = Task.Run(async() =>
            {
                using (var stream = File.Open(
                           sentinelPath,
                           FileMode.CreateNew,
                           FileAccess.ReadWrite,
                           FileShare.Write))
                {
                    await Task.Delay(holdLockTimeout);

                    stream.Close();

                    File.Delete(sentinelPath);
                }
            });

            bool acquiredLock = false;

            // Wait for a lock on the sentinel file.
            var acquiredLockTask = FileHelper.AcquireFileLockAsync(
                sentinelPath,
                clock,
                lockTimeout);

            try
            {
                await lockFileTask;
                acquiredLock = await acquiredLockTask;
            }
            finally
            {
                FileHelper.ReleaseFileLock(sentinelPath);
            }

            Assert.True(acquiredLock);
            // Cleaned up?
            Assert.True(!File.Exists(sentinelPath));
        }
Example #9
0
        public void Test_NoLicense()
        {
            var clock   = new RealClock();
            var mgr     = new LicenseManagerSingleton(ImazenPublicKeys.Test, clock, new StringCacheMem());
            var request = new RequestUrlProvider();

            var conf = new Config();

            conf.Plugins.LicenseScope = LicenseAccess.Local;
            conf.Plugins.Install(new Gradient());
            conf.Plugins.Install(new EmptyLicenseEnforcedPlugin(new LicenseEnforcer <EmptyLicenseEnforcedPlugin>(mgr, mgr, request.Get).EnableEnforcement(), "R4Creative"));

            // We don't watermark outside of http requests (even if there are no valid licenses)
            request.Url = null;
            Assert.False(IsWatermarking(conf, mgr));

            // But we certainly should be, here
            request.Url = new Uri("http://other.co");
            Assert.True(IsWatermarking(conf, mgr));

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