public void GetConfiguration_GetsUnencryptedConfigurationFromAppSettings()
        {
            //create the provider
            var certificateService = new Mock <ICertificateService>().Object;
            var configProvider     = new AuthorizationConfigurationProvider(certificateService);

            WriteAppSettingsToFile(UnencryptedAppSettings);

            var config = configProvider.GetAppConfiguration(Directory.GetCurrentDirectory());

            Assert.Equal("hc", config.ClientName);
            Assert.False(config.ApplicationInsights.Enabled);
            Assert.Equal("test", config.EncryptionCertificateSettings.EncryptionCertificateThumbprint);
        }
        public void GetConfiguration_GetsEncryptedConfigurationFromAppSettings()
        {
            var certificateService = new Mock <ICertificateService>();

            certificateService
            .Setup(certService => certService.GetCertificate(It.IsAny <EncryptionCertificateSettings>()))
            .Returns((EncryptionCertificateSettings settings) => GetCertificate());
            var configProvider = new AuthorizationConfigurationProvider(certificateService.Object);

            WriteAppSettingsToFile(EncryptedAppSettings);

            var config = configProvider.GetAppConfiguration(Directory.GetCurrentDirectory());

            Assert.Equal("password", config.CouchDbSettings.Password);
        }
        public void GetConfiguration_GetsUnencryptedConfigurationFromDockerSecrets()
        {
            var certificateService = new Mock <ICertificateService>().Object;
            var configProvider     = new AuthorizationConfigurationProvider(certificateService);

            WriteAppSettingsToFile(UnencryptedAppSettings);
            CreateDockerSecret("CouchDbSettings__Username", "admin");

            var config = configProvider.GetAppConfiguration(Directory.GetCurrentDirectory());

            Assert.Equal("hc", config.ClientName);
            Assert.Equal(false, config.ApplicationInsights.Enabled);
            Assert.Equal("test", config.CouchDbSettings.Password);
            Assert.Equal("admin", config.CouchDbSettings.Username);
            Assert.Equal("test", config.EncryptionCertificateSettings.EncryptionCertificateThumbprint);
        }
        public void GetConfiguration_GetsUnencryptedConfigurationFromDockerSecrets()
        {
            var certificateService = new Mock <ICertificateService>().Object;
            var configProvider     = new AuthorizationConfigurationProvider(certificateService);

            WriteAppSettingsToFile(UnencryptedAppSettings);
            CreateDockerSecret("ApplicationInsights__InstrumentationKey", "56789");

            var config = configProvider.GetAppConfiguration(Directory.GetCurrentDirectory());

            DeleteDockerSecret("ApplicationInsights__InstrumentationKey");

            Assert.Equal("hc", config.ClientName);
            Assert.False(config.ApplicationInsights.Enabled);
            Assert.Equal("56789", config.ApplicationInsights.InstrumentationKey);
            Assert.Equal("test", config.EncryptionCertificateSettings.EncryptionCertificateThumbprint);
        }
        public void GetConfiguration_GetsEncryptedConfiguration()
        {
            var certificateService = new Mock <ICertificateService>();

            certificateService
            .Setup(certService => certService.GetCertificate(It.IsAny <EncryptionCertificateSettings>()))
            .Returns((EncryptionCertificateSettings settings) => GetCertificate());
            var configProvider = new AuthorizationConfigurationProvider(certificateService.Object);

            CreateDockerSecret("CouchDbSettings__Password", "!!enc!!:gczwrq53rqqMwA6y+4z0ThqU7DQLP9J2Lu+Yy0OpayMZrh73aOZLwS4WAqZ00HUcPsrNQWGxFel1UEuPYx4c8hztddYI6XRpbDgCYvDvJiIxMVnrsekpHwFv2vmVWbxXRw306Rv13oA9xdTbFMvavy2LYT5GgkOpJLAcAxX9b4F1svmiNDeroL6+tNIxN3lX8i2o9GzR94HJltQi+c1pgN3WRDy0Jrgk4dA174xkJuo47CiS0N3ePZMaHz98ok9sUio7lQ8OzL25xp+1mLLVXoywUcKzpJJ+PFTltMXamEzkeH4hNIu5HCngiNqDB09bQ22WElzESIA6dw3iVVjH6g==");

            var config = configProvider.GetAppConfiguration(Directory.GetCurrentDirectory());

            DeleteDockerSecret("CouchDbSettings__Password");

            Assert.Equal("password", config.CouchDbSettings.Password);
        }