Пример #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddAuthorization();

            IPostService        postService        = new PostService();
            IRemoteTokenService remoteTokenService = new RemoteTokenService(postService);

            services.AddAuthorization(options =>
            {
                options.AddPolicy(AuthorizationConfiguration.PolicyName, policy =>
                                  policy.RequireAssertion(context =>
                                                          context.User.HasClaim(c =>
                                                                                (c.Type == AuthorizationConfiguration.PolicyName) &&
                                                                                remoteTokenService.VerifyToken(c.Value))));
            });

            services.AddDistributedMemoryCache();
            services.AddSession();
            services.AddMvc();

            // Database
            services.AddDbContext <AuthServerContext>(
                options => options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));

            return(DependencyInjectionConfigurator.ConfigureContainer(services));
        }
        public void AcquireTokenShouldThrowServerConnectionException()
        {
            // arrange
            var postServiceMock = new Mock <IPostService>();

            postServiceMock.Setup(
                serv => serv.SendAndGetAnswer(It.IsAny <string>(), It.IsAny <Dictionary <string, string> >()))
            .Throws(new Exception());

            IRemoteTokenService remoteTokenService = new RemoteTokenService(postServiceMock.Object);

            // act & assert
            Assert.Throws <ServerConnectionException>(
                () => remoteTokenService.AcquireToken("sample_login", "sample_password"));
        }
        public void AcquireTokenShouldReturnNotValidServerAnswerException()
        {
            // arrange
            var postServiceMock = new Mock <IPostService>();

            postServiceMock.Setup(
                serv => serv.SendAndGetAnswer(It.IsAny <string>(), It.IsAny <Dictionary <string, string> >()))
            .Returns("actually not a valid answer");

            IRemoteTokenService remoteTokenService = new RemoteTokenService(postServiceMock.Object);

            // act & assert
            Assert.Throws <ServerNotValidAnswerException>(
                () => remoteTokenService.AcquireToken("sample_login", "sample_password"));
        }
        public void VerifyTokenShouldReturnFalseBecauseOfNotValidServerAnswer()
        {
            // arrange
            var postServiceMock = new Mock <IPostService>();

            postServiceMock.Setup(
                serv => serv.SendAndGetAnswer(It.IsAny <string>(), It.IsAny <Dictionary <string, string> >()))
            .Returns("actually not a valid answer");

            IRemoteTokenService remoteTokenService = new RemoteTokenService(postServiceMock.Object);
            // act
            var answer = remoteTokenService.VerifyToken("sample_jwt");

            // assert
            Assert.Equal(false, answer);
        }
        public void AcquireTokenShouldReturnSampleJwt()
        {
            // arrange
            var postServiceMock = new Mock <IPostService>();

            postServiceMock.Setup(
                serv => serv.SendAndGetAnswer(It.IsAny <string>(), It.IsAny <Dictionary <string, string> >()))
            .Returns(new JsonObject
            {
                Result = JsonValues.Authenticated,
                Jwt    = "sample_jwt"
            }.ToJson());

            IRemoteTokenService remoteTokenService = new RemoteTokenService(postServiceMock.Object);
            // act
            var answer = remoteTokenService.AcquireToken("sample_login", "sample_password");

            // assert
            Assert.Equal("sample_jwt", answer);
        }
        public void VerifyTokenShouldReturnTrue()
        {
            // arrange
            var postServiceMock = new Mock <IPostService>();

            postServiceMock.Setup(
                serv => serv.SendAndGetAnswer(It.IsAny <string>(), It.IsAny <Dictionary <string, string> >()))
            .Returns(new JsonObject
            {
                Result = JsonValues.TokenValid
            }.ToJson());

            IRemoteTokenService remoteTokenService = new RemoteTokenService(postServiceMock.Object);

            // act
            var answer = remoteTokenService.VerifyToken("sample_jwt");

            // assert
            Assert.Equal(true, answer);
        }
Пример #7
0
 public RemoteController(IRemoteTokenDAL remoteTokenDAL, IRemoteCardUpdateDAL remoteCardUpdateDAL, IRemoteLoggingDAL remoteLoggingDAL)
 {
     _remoteTokenService      = new RemoteTokenService(remoteTokenDAL);
     _remoteCardUpdateService = new RemoteCardUpdateService(remoteCardUpdateDAL);
     _remoteLoggingService    = new RemoteLoggingService(remoteLoggingDAL);
 }
Пример #8
0
 public RemoteController()
 {
     _remoteTokenService      = new RemoteTokenService();
     _remoteCardUpdateService = new RemoteCardUpdateService();
     _remoteLoggingService    = new RemoteLoggingService();
 }