//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); }
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); }
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(); }
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); }
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); }
protected TestBase() { _dbFileName = "ApiGateway_" + _threadCounter++ + ".db"; if (File.Exists(_dbFileName)) { File.Delete(_dbFileName); } _context = new ApiGatewayContext(GetSqliteDbOptions()); //_context.Database.EnsureCreated(); }
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); }
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); }
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); }
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); }
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); }
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); }
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(); }
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); }
public KeyData(ApiGatewayContext context) { _context = context; }
public ServiceManagementService(ApiGatewayContext apiGatewayContext) { _context = apiGatewayContext; }
public UrlValidationService(ApiGatewayContext apiGatewayContext) { _context = apiGatewayContext; }
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"; }
public RoleData(ApiGatewayContext context) { _context = context; }
public ServiceDiscoveryService(ApiGatewayContext dbContext) { _serviceDisplayDAO = new ServiceDiscoveryDAO(dbContext); }
public TeamLoginService(ApiGatewayContext apiGatewayContext) { _context = apiGatewayContext; }
public TeamRegistrationController(ApiGatewayContext apiGatewayContext, TeamRegistrationManager teamRegistrationManager) { _apiGatewayContext = apiGatewayContext; _teamRegistrationManager = teamRegistrationManager; }
public ManageServiceAuthorizationHandler(IHttpContextAccessor httpContextAccessor, ApiGatewayContext apiGatewayContext) { _httpContextAccessor = httpContextAccessor; _apiGatewayContext = apiGatewayContext; }
public TestService(ApiGatewayContext apiGatewayContext) { _apiGatewayContext = apiGatewayContext; }
public TeamRegistrationService(ApiGatewayContext apiGatewayContext) { _context = apiGatewayContext; }
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); }
public ServiceData(ApiGatewayContext context) { _context = context; }
public ServiceDiscoveryDAO(ApiGatewayContext dbContext) { _dbContext = dbContext; }