Exemple #1
0
        public void EnvironmentValidDefaultToFalse(string value)
        {
            Environment.SetEnvironmentVariable("admin_password_hash", "1");
            Environment.SetEnvironmentVariable("unsafe_do_no_validate_user", value);
            Environment.SetEnvironmentVariable("gcp_client_id", "3");
            Environment.SetEnvironmentVariable("aws_domain_name", "4");

            var env = ConfigureAppEnvironment.FromEnv();

            Assert.True(env.SkipValidation == "false", "Skip validation env var is not string false when null.");
        }
Exemple #2
0
        public void EnvironmentDomainSetOrThrow(string value)
        {
            Environment.SetEnvironmentVariable("admin_password_hash", "1");
            Environment.SetEnvironmentVariable("unsafe_do_no_validate_user", "2");
            Environment.SetEnvironmentVariable("gcp_client_id", "3");
            Environment.SetEnvironmentVariable("aws_domain_name", value);

            Assert.Throws <EnvironmentVarNotSet>(() =>
            {
                ConfigureAppEnvironment.FromEnv();
            });
        }
Exemple #3
0
        public async void ValidateUserSkipHasMockId()
        {
            Environment.SetEnvironmentVariable("admin_password_hash", "1");
            Environment.SetEnvironmentVariable("unsafe_do_no_validate_user", "true");
            Environment.SetEnvironmentVariable("gcp_client_id", "3");
            Environment.SetEnvironmentVariable("aws_domain_name", "4");

            var env = ConfigureAppEnvironment.FromEnv();

            var user = await GoogleApi.ValidateUser("dummy", env);

            Assert.True(user.Subject == "123456789109876543210", "Dummy subject when validating is correct.");
        }
Exemple #4
0
        public async void ValidateUserIsNullForDummyToken(string value)
        {
            Environment.SetEnvironmentVariable("admin_password_hash", "1");
            Environment.SetEnvironmentVariable("unsafe_do_no_validate_user", value);
            Environment.SetEnvironmentVariable("gcp_client_id", "3");
            Environment.SetEnvironmentVariable("aws_domain_name", "4");

            var env = ConfigureAppEnvironment.FromEnv();

            var user = await GoogleApi.ValidateUser("dummy", env);

            Assert.True(user == null, "Token failed validation is not null");
        }
Exemple #5
0
        public void EnvironmentIsCapturedDifferently()
        {
            Environment.SetEnvironmentVariable("admin_password_hash", "1");
            Environment.SetEnvironmentVariable("unsafe_do_no_validate_user", "2");
            Environment.SetEnvironmentVariable("gcp_client_id", "3");
            Environment.SetEnvironmentVariable("aws_domain_name", "4");

            var env = ConfigureAppEnvironment.FromEnv();

            Assert.True(env.PasswordHash == "1", "Password hash env var is not captured from the environment.");
            Assert.True(env.SkipValidation == "2", "Skip validation env var is not captured from the environment.");
            Assert.True(env.Audience == "3", "Audience env var is not captured from the environment.");
            Assert.True(env.Domain == "4", "Domain hash env var is not captured from the environment.");
        }
Exemple #6
0
        public void ConfigureServices(IServiceCollection services)
        {
            // Add and configure Carter
            services.AddCarter((options) =>
            {
                options.OpenApi.DocumentTitle = this.appConfig.CarterOptions.OpenApi.DocumentTitle;
                options.OpenApi.ServerUrls    = new[]
                {
                    "http://localhost:8090/api/v1",
                    "https://expcap.xyz/api/v1",
                    "https://expcap2.xyz/api/v1",
                };

                options.OpenApi.Securities = new Dictionary <string, OpenApiSecurity>
                {
                    {
                        "TokenAuthorization",
                        new OpenApiSecurity
                        {
                            Type = OpenApiSecurityType.apiKey,
                            Name = "ExperienceCapture-Access-Token",
                            In   = OpenApiIn.cookie,
                        }
                    },
                };
            });

            // Add custom serialization logic for Enums
            BsonSerializer.RegisterSerializer(new EnumSerializer <ExportOptions>(BsonType.String));
            BsonSerializer.RegisterSerializer(new EnumSerializer <RoleOptions>(BsonType.String));

            // Add repositories based on Mongo
            string mongoUrl = $"mongodb://{AppConfiguration.Mongo.ConnectionString}:{AppConfiguration.Mongo.Port}";
            var    client   = new MongoClient(mongoUrl);
            var    db       = client.GetDatabase("ec");

            var signUpRepo = new SignUpTokenRepository(db);

            services.AddSingleton <IRepository <SignUpTokenSchema> >(signUpRepo);

            var accessRepo = new AccessTokenRepository(db);

            services.AddSingleton <IRepository <AccessTokenSchema> >(accessRepo);

            var claimRepo = new ClaimTokenRepository(db);

            services.AddSingleton <IRepository <ClaimTokenSchema> >(claimRepo);

            var sessionRepo = new SessionRepository(db);

            services.AddSingleton <IRepository <SessionSchema> >(sessionRepo);

            var captureRepo = new CapturesRepository(db);

            services.AddSingleton <IRepository <BsonDocument> >(captureRepo);

            var personRepo = new PersonRepository(db);

            services.AddSingleton <IRepository <PersonSchema> >(personRepo);

            // Add Threading
            var threader = new ExportThreader();

            services.AddSingleton <IThreadExtra>(threader);

            // Add time
            var date = new DateProvider();

            services.AddSingleton <IDateExtra>(date);

            // Add Minio
            string minioUsername = "******";
            string minioPassword = "******";

            string minioHost = $"{AppConfiguration.Minio.ConnectionString}:{AppConfiguration.Minio.Port}";
            var    os        = new MinioClientExtra(minioHost, minioUsername, minioPassword);

            services.AddSingleton <IMinioClient>(os);

            // Add environment
            var env = ConfigureAppEnvironment.FromEnv();

            services.AddSingleton <IAppEnvironment>(env);

            // Add logging
            var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
            var logger        = loggerFactory.CreateLogger <Program>();

            services.AddSingleton <ILogger>(logger);
        }