コード例 #1
0
        //Fail condition for ServiceDiscoveryManager.GetAvailableServices(), when input is too short, return no data
        public void GetServices_NotPass_InputTooShort()
        {   //Arrange
            var expected = false;
            var actual   = false;
            ICollection <ServiceDisplayResp> registeredServices;

            //Act
            using (var context = new ApiGatewayContext())
            {
                var serviceDiscoveryService = new ServiceDiscoveryService(context);
                var serviceDiscoveryManager = new ServiceDiscoveryManager(serviceDiscoveryService);
                //Generate a key that is shorter than requirement
                var randomId = GenerateRandomKey(Constants.clientIdLength - 1);
                registeredServices = serviceDiscoveryManager.GetAvailableServices(randomId);
            }

            //Since input is invalid, the registeredServices should be null
            if (registeredServices != null)
            {
                actual = true;
            }

            //Assert
            Assert.AreEqual(expected, actual);
        }
コード例 #2
0
        public void GetServices_NotPass_NullInput()
        {   //Arrange
            var expected = false;
            var actual   = false;
            ICollection <ServiceDisplayResp> registeredServices;

            //Act
            using (var context = new ApiGatewayContext())
            {
                var serviceDiscoveryService = new ServiceDiscoveryService(context);
                var serviceDiscoveryManager = new ServiceDiscoveryManager(serviceDiscoveryService);
                registeredServices = serviceDiscoveryManager.GetAvailableServices(null);
            }



            //Since input is invalid, the registeredServices should be null
            if (registeredServices != null)
            {
                actual = true;
            }

            //Assert
            Assert.AreEqual(expected, actual);
        }
コード例 #3
0
        public void CreateValidTeamPass(TeamRegisterPost request)
        {
            // Arrange DI of objects
            var _context = new ApiGatewayContext();
            var teamRegistrationService = new TeamRegistrationService(_context);
            var urlValidationService    = new UrlValidationService(_context);

            var teamRegistrationManager = new TeamRegistrationManager(teamRegistrationService, urlValidationService);

            // Act create a valid team
            var creatTeamStatus = teamRegistrationManager.CreateTeamAccount(request);

            // Assert that team creation is successfull
            Assert.IsTrue(creatTeamStatus.TeamCreate);

            // Cleanup the team

            var createdTeam = _context.Team.
                              Where(t => request.Username == t.Username).
                              FirstOrDefault();

            if (createdTeam == null)
            {
                // Failed to delete
                Assert.IsTrue(false);
            }
            _context.Team.Remove(createdTeam);
            _context.SaveChanges();
        }
コード例 #4
0
        public void GetServices_NotPass_EmptyDatabase()
        {   //Arrange
            var expected = false;
            var actual   = false;
            ICollection <ServiceDisplayResp> registeredServices;
            var option = new DbContextOptionsBuilder <ApiGatewayContext>()
                         .UseInMemoryDatabase(databaseName: "ServiceDiscoveryDAO_GetServices_Empty_database")
                         .Options;

            //Act
            using (var context = new ApiGatewayContext(option))
            {
                var serviceDiscoveryDAO = new ServiceDiscoveryDAO(context);
                registeredServices = serviceDiscoveryDAO.GetServices(GenerateRandomKey(Int32.Parse(Environment.GetEnvironmentVariable("APIKeyInputLength", EnvironmentVariableTarget.User))));
            }

            //Since input is invalid, the registeredServices should be null
            if (registeredServices != null)
            {
                actual = true;
            }

            //Assert
            Assert.AreEqual(expected, actual);
        }
コード例 #5
0
        public void IfClientExist_InMemory_Pass()
        {   //Arrange
            var expected = true;
            var actual   = false;
            var option   = new DbContextOptionsBuilder <ApiGatewayContext>()
                           .UseInMemoryDatabase(databaseName: "ServiceDiscoveryDAO_IfClientExist_Pass_database")
                           .Options;

            //Act
            using (var context = new ApiGatewayContext(option))
            {
                var teamForTesting = new Team();
                var randomKey      = GenerateRandomKey(Int32.Parse(Environment.GetEnvironmentVariable("APIKeyInputLength", EnvironmentVariableTarget.User)));
                teamForTesting.ClientId    = randomKey;
                teamForTesting.WebsiteUrl  = "testingWebSiteUrl";
                teamForTesting.Secret      = "testingSecret";
                teamForTesting.CallbackUrl = "testingCallBackUrl";
                teamForTesting.Digest      = "testingDigest";
                teamForTesting.Username    = "******";
                context.Team.Add(teamForTesting);
                context.SaveChanges();

                var serviceDiscoveryDAO = new ServiceDiscoveryDAO(context);

                //Different from GetServices, check if a team exist need the same random key
                actual = serviceDiscoveryDAO.IfClientExist(randomKey);
            }

            //Assert
            Assert.AreEqual(expected, actual);
        }
コード例 #6
0
        protected TestBase()
        {
            _dbFileName = "ApiGateway_" + _threadCounter++ + ".db";

            if (File.Exists(_dbFileName))
            {
                File.Delete(_dbFileName);
            }

            _context = new ApiGatewayContext(GetSqliteDbOptions());
            //_context.Database.EnsureCreated();
        }
コード例 #7
0
        public void InvalidNonExistentAccountLoginFail(TeamLoginPost teamLoginPost)
        {
            // DI of team login
            var _context         = new ApiGatewayContext();
            var teamLoginService = new TeamLoginService(_context);
            var jwtService       = new JWTService();

            var teamLoginManager = new TeamLoginManager(teamLoginService, jwtService);

            // Act login for the registered user.
            var loginresp = teamLoginManager.TeamLogin(teamLoginPost);

            // Assert that login fail
            Assert.IsFalse(loginresp.Status);
        }
コード例 #8
0
        public void CreateInvalidTeamInvalidUrlFail(TeamRegisterPost request)
        {
            // Arrange DI of objects
            var _context = new ApiGatewayContext();
            var teamRegistrationService = new TeamRegistrationService(_context);
            var urlValidationService    = new UrlValidationService(_context);

            var teamRegistrationManager = new TeamRegistrationManager(teamRegistrationService, urlValidationService);

            // Act create a valid team
            var creatTeamStatus = teamRegistrationManager.CreateTeamAccount(request);

            // Assert that team creation is successfull
            Assert.IsFalse(creatTeamStatus.TeamCreate);
        }
コード例 #9
0
        public void IfClientExist_WhiteSpaceInput()
        {   //Arrange
            var expected = false;
            var actual   = false;

            //Act
            using (var context = new ApiGatewayContext())
            {
                var serviceDiscoveryDAO = new ServiceDiscoveryDAO(context);
                actual = serviceDiscoveryDAO.IfClientExist("");
            }

            //Assert
            Assert.AreEqual(expected, actual);
        }
コード例 #10
0
        public void IfClientExist_NullInput()
        {   //Arrange
            var expected = false;
            var actual   = false;

            //Act
            using (var context = new ApiGatewayContext())
            {
                var serviceDiscoverService = new ServiceDiscoveryService(context);
                actual = serviceDiscoverService.IfClientExist(null);
            }

            //Assert
            Assert.AreEqual(expected, actual);
        }
コード例 #11
0
        public void IfClientExist_InMemory_EmptyDatabase()
        {   //Arrange
            var expected = false;
            var actual   = false;
            var option   = new DbContextOptionsBuilder <ApiGatewayContext>()
                           .UseInMemoryDatabase(databaseName: "ServiceDiscoveryDAO_IfClientExist_NotPass_database")
                           .Options;

            //Act
            using (var context = new ApiGatewayContext(option))
            {
                var serviceDiscoveryDAO = new ServiceDiscoveryDAO(context);
                var inputClientId       = GenerateRandomKey(Int32.Parse(Environment.GetEnvironmentVariable("APIKeyInputLength", EnvironmentVariableTarget.User)));

                actual = serviceDiscoveryDAO.IfClientExist(inputClientId);
            }

            //Assert
            Assert.AreEqual(expected, actual);
        }
コード例 #12
0
        public void GetServices_NotPass_WhiteSpaceInput()
        {   //Arrange
            var expected = false;
            var actual   = false;
            ICollection <ServiceDisplayResp> registeredServices;

            //Act
            using (var context = new ApiGatewayContext())
            {
                var serviceDiscoveryDAO = new ServiceDiscoveryDAO(context);
                registeredServices = serviceDiscoveryDAO.GetServices("");
            }

            //Since input is invalid, the registeredServices should be null
            if (registeredServices != null)
            {
                actual = true;
            }

            //Assert
            Assert.AreEqual(expected, actual);
        }
コード例 #13
0
        public void InvalidTeamLoginWrongUsernameFail(TeamRegisterPost teamRegisterPost, TeamLoginPost teamLoginPost)
        {
            // Arrange DI of objects
            var _context = new ApiGatewayContext();
            var teamRegistrationService = new TeamRegistrationService(_context);
            var urlValidationService    = new UrlValidationService(_context);

            var teamRegistrationManager = new TeamRegistrationManager(teamRegistrationService, urlValidationService);

            var creatTeamStatus = teamRegistrationManager.CreateTeamAccount(teamRegisterPost);

            // Assert that team creation is successfull
            Assert.IsTrue(creatTeamStatus.TeamCreate);

            // DI of team login
            var teamLoginService = new TeamLoginService(_context);
            var jwtService       = new JWTService();

            var teamLoginManager = new TeamLoginManager(teamLoginService, jwtService);

            // Act login for the registered user.
            var loginresp = teamLoginManager.TeamLogin(teamLoginPost);

            // Assert that login fail
            Assert.IsFalse(loginresp.Status);

            // Cleanup the team
            var createdTeam = _context.Team.
                              Where(t => teamRegisterPost.Username == t.Username).
                              FirstOrDefault();

            if (createdTeam == null)
            {
                // Failed to delete
                Assert.IsTrue(false);
            }
            _context.Team.Remove(createdTeam);
            _context.SaveChanges();
        }
コード例 #14
0
        public void IfClientExist_InMemory_ClientDoesnotMatch()
        {   //Arrange
            var expected = false;
            var actual   = false;
            var option   = new DbContextOptionsBuilder <ApiGatewayContext>()
                           .UseInMemoryDatabase(databaseName: "ServiceDiscoveryDAO_IfClientExist_NotPass_database")
                           .Options;

            //Act
            using (var context = new ApiGatewayContext(option))
            {
                // Create a team first
                var teamForTesting = new Team();
                var randomId       = GenerateRandomKey(Int32.Parse(Environment.GetEnvironmentVariable("APIKeyInputLength", EnvironmentVariableTarget.User)));
                teamForTesting.ClientId    = randomId;
                teamForTesting.WebsiteUrl  = "testingWebSiteUrl";
                teamForTesting.Secret      = "testingSecret";
                teamForTesting.CallbackUrl = "testingCallBackUrl";
                teamForTesting.Digest      = "testingDigest";
                teamForTesting.Username    = "******";
                context.Team.Add(teamForTesting);

                var serviceDiscoveryDAO = new ServiceDiscoveryDAO(context);
                var inputClientId       = GenerateRandomKey(Int32.Parse(Environment.GetEnvironmentVariable("APIKeyInputLength", EnvironmentVariableTarget.User)));

                //Make sure the second random generated clientId is different from the first one
                while (inputClientId == randomId)
                {
                    inputClientId = GenerateRandomKey(Int32.Parse(Environment.GetEnvironmentVariable("APIKeyInputLength", EnvironmentVariableTarget.User)));
                }

                actual = serviceDiscoveryDAO.IfClientExist(inputClientId);
            }

            //Assert
            Assert.AreEqual(expected, actual);
        }
コード例 #15
0
 public KeyData(ApiGatewayContext context)
 {
     _context = context;
 }
コード例 #16
0
 public ServiceManagementService(ApiGatewayContext apiGatewayContext)
 {
     _context = apiGatewayContext;
 }
コード例 #17
0
 public UrlValidationService(ApiGatewayContext apiGatewayContext)
 {
     _context = apiGatewayContext;
 }
コード例 #18
0
ファイル: Program.cs プロジェクト: Jason7539/API_Gateway
        static void Main(string[] args)
        {
            /////////////////// MAKING TOKENS /////////////////
            //var jwtService = new JWTService();

            //var token = jwtService.GenerateHmacSignedJWTToken("myClient", "read", Constants.Issuer, DateTime.Now.ToUniversalTime(), DateTime.Now.AddDays(10).ToUniversalTime(),
            //                                        Constants.SigningKey);
            //// now we have string repre of token lets validate it

            //var handler = new JwtSecurityTokenHandler().ReadJwtToken(token);

            //var claims = handler.Claims.Where(x => x.Type == "aud").FirstOrDefault().Value;


            ////foreach (var item in claims)
            ////{
            ////    Console.WriteLine(item);
            ////}
            //Console.WriteLine(claims);
            //// create fake key.

            //Console.WriteLine(token);



            /////////////////////// TESTING TOKEN VALIDITY /////////////////////////
            //var validationReq = new TokenValidationParameters();
            //validationReq.IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes("asdasds"));
            //validationReq.ValidAudience = "myClient";
            //validationReq.ValidateAudience = true;
            //validationReq.ValidIssuer = Constants.Issuer;

            //validationReq.ValidateIssuerSigningKey = true;
            //validationReq.RequireSignedTokens = true;
            //validationReq.ValidateIssuer = true;
            //validationReq.ValidateLifetime = true;

            //Console.WriteLine(token);

            //var evilToken = token + "asdasd";


            //var outToken = handler.ReadToken(token);


            //var result = handler.ValidateToken(token, validationReq, out outToken);

            //Console.WriteLine(result);



            //////////////////////// RANDOM TEST /////////////////

            var sms = new ServiceManagementService(new ApiGatewayContext());

            var usernames = sms.GetAllowedConfigurationUsers("panic");

            //var teams = sms.GetTeamsUsername();

            //foreach(var t in teams)
            //{
            //    Console.WriteLine(t);
            //}


            //var configjson = JsonSerializer.Deserialize<ServiceConfiguration>(config);  // system.text

            using var _apiGatewayContext = new ApiGatewayContext();
            var resource   = "asdasda";
            var scopeclaim = "jasonjason";

            var owner = from team in _apiGatewayContext.Team
                        join service in _apiGatewayContext.Service on team.ClientId equals service.Owner
                        where resource == service.Endpoint && scopeclaim == team.Username
                        select team.Username;

            var balh = "asdasd";
        }
コード例 #19
0
ファイル: RoleData.cs プロジェクト: shahedk/ApiGateway
 public RoleData(ApiGatewayContext context)
 {
     _context = context;
 }
コード例 #20
0
 public ServiceDiscoveryService(ApiGatewayContext dbContext)
 {
     _serviceDisplayDAO = new ServiceDiscoveryDAO(dbContext);
 }
コード例 #21
0
 public TeamLoginService(ApiGatewayContext apiGatewayContext)
 {
     _context = apiGatewayContext;
 }
コード例 #22
0
 public TeamRegistrationController(ApiGatewayContext apiGatewayContext, TeamRegistrationManager teamRegistrationManager)
 {
     _apiGatewayContext       = apiGatewayContext;
     _teamRegistrationManager = teamRegistrationManager;
 }
コード例 #23
0
 public ManageServiceAuthorizationHandler(IHttpContextAccessor httpContextAccessor, ApiGatewayContext apiGatewayContext)
 {
     _httpContextAccessor = httpContextAccessor;
     _apiGatewayContext   = apiGatewayContext;
 }
コード例 #24
0
ファイル: TestService.cs プロジェクト: Jason7539/API_Gateway
 public TestService(ApiGatewayContext apiGatewayContext)
 {
     _apiGatewayContext = apiGatewayContext;
 }
コード例 #25
0
 public TeamRegistrationService(ApiGatewayContext apiGatewayContext)
 {
     _context = apiGatewayContext;
 }
コード例 #26
0
        public void GetServices_InMemory_Pass()
        {   //Arrange
            var expected = true;
            var actual   = false;
            var option   = new DbContextOptionsBuilder <ApiGatewayContext>()
                           .UseInMemoryDatabase(databaseName: "ServiceDiscoveryDAO_GetServices_Pass_Database")
                           .Options;
            ICollection <ServiceDisplayResp> registeredServices;

            //Act
            using (var context = new ApiGatewayContext(option))
            {
                // Create a team first
                var teamForTesting = new Team();
                var randomId       = GenerateRandomKey(Int32.Parse(Environment.GetEnvironmentVariable("APIKeyInputLength", EnvironmentVariableTarget.User)));
                teamForTesting.ClientId    = randomId;
                teamForTesting.WebsiteUrl  = "testingWebSiteUrl";
                teamForTesting.Secret      = "testingSecret";
                teamForTesting.CallbackUrl = "testingCallBackUrl";
                teamForTesting.Digest      = "testingDigest";
                teamForTesting.Username    = "******";
                context.Team.Add(teamForTesting);

                //Service

                var serviceForTesting = new Service();
                serviceForTesting.Endpoint    = "testingEndPoint";
                serviceForTesting.Owner       = randomId;//need to be the same as team's ClineId
                serviceForTesting.Id          = 12345678;
                serviceForTesting.Input       = "int";
                serviceForTesting.Output      = "int";
                serviceForTesting.Dataformat  = "xml";
                serviceForTesting.Description = "Some description for testing";
                context.Service.Add(serviceForTesting);

                //Configuration

                var configForTesting = new Configuration();
                configForTesting.EndPoint = "testingEndPoint";//need to be the same as service
                configForTesting.OpenTo   = randomId;
                configForTesting.Steps    = "some steps for testing";
                context.Configuration.Add(configForTesting);
                context.SaveChanges();

                var serviceDiscoveryDAO = new ServiceDiscoveryDAO(context);

                registeredServices = serviceDiscoveryDAO.GetServices(randomId);
                if (registeredServices.Count > 0)
                {
                    actual = true;
                }
            }

            foreach (var service in registeredServices)
            {
                Trace.WriteLine(service.Endpoint + " " + service.Username + " " + service.Input + " " + service.Output + " " + service.Dataformat + " " + service.Description + Environment.NewLine);
            }

            //Assert
            Assert.AreEqual(expected, actual);
        }
コード例 #27
0
 public ServiceData(ApiGatewayContext context)
 {
     _context = context;
 }
コード例 #28
0
 public ServiceDiscoveryDAO(ApiGatewayContext dbContext)
 {
     _dbContext = dbContext;
 }