Exemplo n.º 1
0
        public void Case07()
        {
            var simAndDevice = new SimAndDevice()
            {
                Sim                    = _sim2,
                Device                 = _device1,
                IsolatedNw2Ip          = "127.0.0.1/18",
                AuthenticationDuration = 1,
                StartDate              = DateTime.Parse("2020-02-01"),
                EndDate                = DateTime.Parse("2020-02-09")
            };

            _context.Add(simAndDevice);
            _context.SaveChanges();
            var obj = new
            {
                IsolatedNw2Ip          = "127.0.0.1/18",
                AuthenticationDuration = 1,
                StartDate = "2020-02-01",
                EndDate   = "2020-02-09"
            };

            var(response, _, json) = Utils.Put(_client, $"{Url}/{simAndDevice.Id}", Utils.CreateJsonContent(obj), "user1", "user1", 1, "domain01"); // ユーザー管理者
            Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
            Assert.NotNull(json["traceId"]);                                                                                                        // 存在
            Assert.NotNull(json["errors"]["Role"]);
        }
Exemplo n.º 2
0
        public void Case13()
        {
            SetUpData();
            for (int j = 1; j <= 2; j++)
            {
                for (int i = 1; i <= 25; i++)
                {
                    var simDevice = new SimAndDevice() // 正常データ
                    {
                        Sim                    = _sim1,
                        Device                 = _device1,
                        IsolatedNw2Ip          = $"127.0.0.{i:00}",
                        AuthenticationDuration = i,
                        StartDate              = DateTime.Parse($"2020-{j:00}-{i:00}"),
                        EndDate                = DateTime.Parse($"2021-{j:00}-{i:00}"),
                    };
                    _context.AddRange(simDevice);
                }
            }
            _context.SaveChanges();
            var(response, _, json) = Utils.Get(_client, $"{Url}/?page=2&Msisdn=msisdn&DeviceName=device&startDateFrom=2019-12-29&startDateTo=2020-02-27&endDateFrom=2020-12-29&endDateTo=2021-02-27&IsAuthenticationDone=False&sortBy=endDate&orderBy=desc", "user1", "user1", 1, "domain01");  // ユーザー管理者
            var list = (JArray)json["results"];

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal(20, list.Count);
            Assert.Equal(50, (int)json["count"]);
            Assert.Equal("2021-02-05", list[0]["endDate"]);
            Assert.Equal("2021-02-04", list[1]["endDate"]); // 利用終了日ソート:'降順
        }
Exemplo n.º 3
0
        public void Case16()
        {
            SetUpData();
            for (int j = 1; j <= 2; j++)
            {
                for (int i = 1; i <= 25; i++)
                {
                    var simDeviceAuthenticationStateDone = new SimAndDeviceAuthenticated()
                    {
                        Expiration = DateTime.Now.AddHours(6.00)
                    };
                    var simDevice = new SimAndDevice() // 正常データ
                    {
                        Sim                       = _sim1,
                        Device                    = _device1,
                        IsolatedNw2Ip             = $"127.0.0.{i:00}",
                        AuthenticationDuration    = i,
                        StartDate                 = DateTime.Parse($"2020-{j:00}-{i:00}"),
                        EndDate                   = DateTime.Parse($"2021-{j:00}-{i:00}"),
                        SimAndDeviceAuthenticated = simDeviceAuthenticationStateDone
                    };
                    _context.AddRange(simDevice, simDeviceAuthenticationStateDone);
                }
            }
            _context.SaveChanges();
            var(response, _, json) = Utils.Get(_client, $"{Url}/?OrganizationCode={_org1.Code}&page=1&pageSize=2&Msisdn=msisdn&DeviceName=device&startDateFrom=2019-12-29&startDateTo=2020-02-27&endDateFrom=2020-12-29&endDateTo=2021-02-27&IsAuthenticationDone=True&sortBy=endDate&orderBy=asc", "user0", "user0"); //    スーパー管理者
            var list = (JArray)json["results"];

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal(2, list.Count);
            Assert.Equal(50, (int)json["count"]);
            Assert.Equal("2021-01-01", list[0]["endDate"]);
            Assert.Equal("2021-01-02", list[1]["endDate"]);// 利用終了日ソート:'昇順
        }
Exemplo n.º 4
0
        public void Case05()
        {
            var simDeviceAuthenticationStateDone = new SimAndDeviceAuthenticated()
            {
                Expiration = DateTime.Now.AddHours(1.00)
            };
            var simDevice1 = new SimAndDevice() // 組織 : '自組織
            {
                Sim                       = _sim1,
                Device                    = _device1,
                IsolatedNw2Ip             = "127.0.0.1",
                AuthenticationDuration    = 1,
                StartDate                 = DateTime.Parse("2020-02-07"),
                SimAndDeviceAuthenticated = simDeviceAuthenticationStateDone
            };

            _context.Add(simDeviceAuthenticationStateDone);
            _context.Add(simDevice1);
            _context.SaveChanges();
            var(response, _, json) = Utils.Get(_client, $"{Url}/{simDevice1.Id}", "user1", "user1", 1, "domain01");  // ユーザー管理者
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal(simDevice1.Id.ToString(), json["id"]);
            Assert.Equal(simDevice1.Sim.Msisdn, json["sim"]["msisdn"]);
            Assert.Equal(simDevice1.Device.Name, json["device"]["name"]);
            Assert.Equal(simDevice1.IsolatedNw2Ip, json["isolatedNw2Ip"]);
            Assert.Equal(simDevice1.AuthenticationDuration, json["authenticationDuration"]);
            Assert.Equal(simDevice1.StartDate.ToString("yyyy-MM-dd"), json["startDate"]);
            Assert.Null(json["endDate"].FirstOrDefault());
            Assert.Equal(simDeviceAuthenticationStateDone.Id, json["simAndDeviceAuthenticated"]["id"]);
        }
Exemplo n.º 5
0
        public ListingMineTests(CustomWebApplicationFactoryWithMariaDb <JinCreek.Server.Admin.Startup> factory)
        {
            _client  = factory.CreateClient();
            _context = factory.Services.GetService <IServiceScopeFactory>().CreateScope().ServiceProvider.GetService <MainDbContext>();

            Utils.RemoveAllEntities(_context);

            _context.Add(_org1    = Utils.CreateOrganization(code: 1, name: "org1"));
            _context.Add(_org2    = Utils.CreateOrganization(code: 2, name: "org2"));
            _context.Add(_domain1 = new Domain {
                Id = Guid.NewGuid(), Name = "domain1", OrganizationCode = _org1.Code
            });
            _context.Add(_domain2 = new Domain {
                Id = Guid.NewGuid(), Name = "domain2", OrganizationCode = _org2.Code
            });
            _context.Add(_user0 = new SuperAdmin {
                AccountName = "user0", Name = "", Password = Utils.HashPassword("user0")
            });                                                                                                                 // スーパー管理者
            _context.Add(_user1 = new UserAdmin {
                AccountName = "user1", Name = "", Password = Utils.HashPassword("user1"), Domain = _domain1
            });                                                                                                                                   // ユーザー管理者
            _context.Add(_user2 = new GeneralUser {
                AccountName = "xuser2a", Name = "", Domain = _domain1
            });
            _context.Add(_simGroup1 = Utils.CreateSimGroup(organization: _org1, name: "simGroup1", isolatedNw1IpPool: "isolatedNw1IpPool"));
            _context.Add(_simGroup2 = Utils.CreateSimGroup(organization: _org2, name: "simGroup2", isolatedNw1IpPool: "isolatedNw1IpPool"));
            _context.Add(_sim1A     = new Sim {
                SimGroup = _simGroup1, Msisdn = "1", Imsi = "1a", IccId = "1a", UserName = "******", Password = "******"
            });
            _context.Add(_sim1B = new Sim {
                SimGroup = _simGroup1, Msisdn = "0123456789", Imsi = "1b", IccId = "1b", UserName = "******", Password = "******"
            });
            _context.Add(_sim2 = new Sim {
                SimGroup = _simGroup2, Msisdn = "2", Imsi = "2", IccId = "2", UserName = "******", Password = "******"
            });
            _context.Add(_device1    = Utils.CreateDevice(domain: _domain1, name: "device1"));
            _context.Add(_device2    = Utils.CreateDevice(domain: _domain1, name: "xdevice2a"));
            _context.Add(_simDevice1 = new SimAndDevice {
                Id = Guid.NewGuid(), SimId = _sim1A.Id, Device = _device1, IsolatedNw2Ip = ""
            });
            _context.Add(_simDevice2 = new SimAndDevice {
                Id = Guid.NewGuid(), SimId = _sim1A.Id, Device = _device2, IsolatedNw2Ip = ""
            });
            _context.Add(_multiFactor1 = new MultiFactor {
                Id = Guid.NewGuid(), SimAndDevice = _simDevice1, EndUserId = _user1.Id, ClosedNwIp = ""
            });
            _context.Add(_multiFactor2 = new MultiFactor {
                Id = Guid.NewGuid(), SimAndDevice = _simDevice2, EndUserId = _user2.Id, ClosedNwIp = ""
            });

            //_context.Add(new SimAndDeviceAuthenticationSuccessLog { Id = Guid.NewGuid(), SimAndDevice = _simDevice1 });
            //_context.Add(new SimAndDeviceAuthenticationFailureLog { Id = Guid.NewGuid(), Sim = _sim1 });
            //_context.Add(new MultiFactorAuthenticationSuccessLog { Id = Guid.NewGuid(), MultiFactor = _factorCombination1 });
            //_context.Add(new MultiFactorAuthenticationFailureLog { Id = Guid.NewGuid(), SimAndDevice = _simDevice1 });
            //_context.Add(new DeauthenticationLog { Id = Guid.NewGuid(), MultiFactor = _factorCombination1 });
            _context.SaveChanges();
        }
Exemplo n.º 6
0
        public void Case04()
        {
            var simDevice1 = new SimAndDevice() // 組織 : '自組織 SIM(MSISDN):'フィルターに合致
            {
                Sim                    = _sim1,
                Device                 = _device1,
                IsolatedNw2Ip          = "127.0.0.1",
                AuthenticationDuration = 1,
                StartDate              = DateTime.Parse("2020-02-07"),
            };
            var simDevice4 = new SimAndDevice() // 組織 : '自組織 SIM(MSISDN):'フィルターに合致
            {
                Sim                    = _sim1a,
                Device                 = _device1,
                IsolatedNw2Ip          = "127.0.0.1",
                AuthenticationDuration = 1,
                StartDate              = DateTime.Parse("2020-02-07"),
            };
            var simDevice2 = new SimAndDevice() // 組織 : '自組織 SIM(MSISDN):'フィルターに合致せず
            {
                Sim = new Sim()                 // 組織 : '自組織
                {
                    Msisdn   = "abcdfe",
                    Imsi     = "12",
                    IccId    = "11111",
                    UserName = "******",
                    Password = "******",
                    SimGroup = _simGroup1
                },
                Device                 = _device1,
                IsolatedNw2Ip          = "127.0.0.1",
                AuthenticationDuration = 1,
                StartDate              = DateTime.Parse("2020-02-07"),
            };
            var simDevice3 = new SimAndDevice() // 組織 : '他組織 SIM(MSISDN):'フィルターに合致
            {
                Sim                    = _sim2,
                Device                 = _device1,
                IsolatedNw2Ip          = "127.0.0.1",
                AuthenticationDuration = 1,
                StartDate              = DateTime.Parse("2020-02-07"),
            };

            _context.AddRange(simDevice3, simDevice1, simDevice2, simDevice4);
            _context.SaveChanges();
            var(response, _, json) = Utils.Get(_client, $"{Url}/?page=1&Msisdn=msisdn&sortBy=Msisdn&orderBy=asc", "user1", "user1", 1, "domain01");  // ユーザー管理者
            var list = (JArray)json["results"];

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.NotEmpty(list);
            Assert.Equal(2, list.Count);
            Assert.Equal(2, (int)json["count"]);
            Assert.Equal("msisdn01", list[0]["sim"]["msisdn"]); // SIM(MSISDN)ソート:'昇順
            Assert.Equal("msisdn01a", list[1]["sim"]["msisdn"]);
        }
        private void CreateSimAndDeviceAuthenticationSuccessLog(SimAndDevice simAndDevice)
        {
            var simAndDeviceAuthenticationSuccessLog = new SimAndDeviceAuthenticationSuccessLog
            {
                SimAndDevice = simAndDevice,
                Time         = DateTime.Now,
                Sim          = simAndDevice.Sim
            };

            _authenticationRepository.Create(simAndDeviceAuthenticationSuccessLog);
        }
Exemplo n.º 8
0
        public MultiFactor GetFactorCombination(string account, SimAndDevice simAndDevice)
        {
            var factorCombination = _mainDbContext.MultiFactor
                                    .AsNoTracking()
                                    .Include(fc => fc.SimAndDevice)
                                    .Include(fc => fc.EndUser)
                                    .Include(fc => fc.MultiFactorAuthenticated)
                                    .Where(fc => fc.EndUser.AccountName == account &&
                                           fc.SimAndDevice.Id == simAndDevice.Id)
                                    .FirstOrDefault();

            return(factorCombination);
        }
        private void CreateSimAndDeviceRecords()
        {
            SimAndDevice1 = new SimAndDevice()
            {
                Sim                    = Sim1,
                Device                 = Device1,
                IsolatedNw2Ip          = "192.168.10.1",
                AuthenticationDuration = 2,
                StartDate              = CurrentDateTimeForStart.Item1,
                EndDate                = CurrentDateTimeForStart.Item2,
            };

            MainDbContext.AddRange(SimAndDevice1);
        }
Exemplo n.º 10
0
        public void Case01()
        {
            var simDevice1 = new SimAndDevice() // 組織 : '自組織
            {
                Sim                    = _sim1,
                Device                 = _device1,
                IsolatedNw2Ip          = "127.0.0.1",
                AuthenticationDuration = 1,
                StartDate              = DateTime.Parse("2020-02-07"),
                EndDate                = DateTime.Now.AddHours(6.00)
            };
            var simDevice2 = new SimAndDevice() // 組織 : '自組織
            {
                Sim                    = _sim1a,
                Device                 = _device1,
                IsolatedNw2Ip          = "127.0.0.1",
                AuthenticationDuration = 1,
                StartDate              = DateTime.Parse("2020-02-07"),
            };
            var simDevice3 = new SimAndDevice() // 組織 : '自組織
            {
                Sim                    = _sim1a,
                Device                 = _device2,
                IsolatedNw2Ip          = "127.0.0.1",
                AuthenticationDuration = 1,
                StartDate              = DateTime.Parse("2020-02-07"),
            };
            var simDevice5 = new SimAndDevice() // 組織 : '他組織
            {
                Sim                    = _sim2,
                Device                 = _device1,
                IsolatedNw2Ip          = "127.0.0.1",
                AuthenticationDuration = 1,
                StartDate              = DateTime.Parse("2020-02-07"),
            };

            _context.AddRange(simDevice5, simDevice1, simDevice2, simDevice3);
            _context.SaveChanges();
            var(response, _, json) = Utils.Get(_client, $"{Url}/?", "user1", "user1", 1, "domain01");  // ユーザー管理者
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            var list = (JArray)json["results"];

            Assert.Equal(3, list.Count);
            Assert.Equal(3, (int)json["count"]);
            Assert.Equal("msisdn01", list[0]["sim"]["msisdn"]);
            Assert.Equal("msisdn01a", list[1]["sim"]["msisdn"]); //SIM(MSISDN)ソート:'昇順
            Assert.Equal("device01", list[1]["device"]["name"]);
            Assert.Equal("device02", list[2]["device"]["name"]); // 端末ソート:'昇順
        }
        public SimAndDevice SetUpInsertDataForDeauthenticationCase13()
        {
            var simDevice = new SimAndDevice
            {
                Sim                    = Sim,
                Device                 = Device,
                IsolatedNw2Ip          = "Nw2Address",
                StartDate              = DateTime.Now.AddHours(-6.00),
                EndDate                = DateTime.Now.AddHours(6.00),
                AuthenticationDuration = 1
            };

            MainDbContext.AddRange(simDevice);
            MainDbContext.SaveChanges();
            return(simDevice);
        }
Exemplo n.º 12
0
        public void Case19()
        {
            var sim1 = new Sim()  //自組織
            {
                Msisdn   = "1001",
                Imsi     = "1001",
                IccId    = "1001",
                UserName = "******",
                Password = "******",
                SimGroup = _simGroup1
            };
            var sim2 = new Sim() // 自組織
            {
                Msisdn   = "1002",
                Imsi     = "1002",
                IccId    = "1002",
                UserName = "******",
                Password = "******",
                SimGroup = _simGroup1
            };
            var simAndDevice = new SimAndDevice()
            {
                Sim                    = sim2,
                Device                 = _device1,
                IsolatedNw2Ip          = "127.0.0.1/18",
                AuthenticationDuration = 1,
                StartDate              = DateTime.Parse("2020-02-01"),
                EndDate                = DateTime.Parse("2020-02-09")
            };

            _context.AddRange(sim1, sim2, simAndDevice);
            _context.SaveChanges();

            var obj = new StringBuilder();

            obj.AppendLine("is Delete,ID,SIM Group ID,SIM Group Name,MSISDN,IMSI,ICC ID,User Name,Password");
            obj.AppendLine($"a,{sim1.Id},{_simGroup1.Id},{_simGroup1.Name},{sim1.Msisdn},{sim1.Imsi},{sim1.IccId},sim001,123456");
            obj.AppendLine($"D,{sim2.Id},{_simGroup1.Id},{_simGroup1.Name},{sim2.Msisdn},{sim2.Imsi},{sim2.IccId},sim003,123456");                   //SimDeviceも存在

            var(response, body, _) = Utils.Post(_client, $"{Url}", Utils.CreateFormContent(obj.ToString(), "csv"), "user1", "user1", 1, "domain01"); // ユーザー管理者
            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
            var json = JObject.Parse(body);

            Assert.NotNull(json["traceId"]); // 存在
            Assert.NotNull(json["errors"][nameof(SimAndDevice)]);
        }
Exemplo n.º 13
0
        public ActionResult <SimAndDevice> PostSimAndDevice(RegisterParam param)
        {
            var sim    = _userRepository.GetSim((Guid)param.SimId);
            var device = _userRepository.GetDevice((Guid)param.DeviceId);

            if (param.StartDate < device.StartDate || param.StartDate > device.EndDate)
            {
                ModelState.AddModelError(nameof(param.StartDate), Messages.OutOfDate);
            }
            if (param.EndDate < device.StartDate || param.EndDate > device.EndDate)
            {
                ModelState.AddModelError(nameof(param.EndDate), Messages.OutOfDate);
            }
            if (!ModelState.IsValid)
            {
                return(ValidationProblem(ModelState));
            }

            var simDevice = new SimAndDevice()
            {
                Sim       = sim,
                Device    = device,
                StartDate = (DateTime)param.StartDate,
                EndDate   = param.EndDate,
                AuthenticationDuration = (int)param.AuthenticationDuration,
                IsolatedNw2Ip          = param.IsolatedNw2Ip
            };

            if (_context.SimAndDevice.Any(s => s.Sim.Id == simDevice.Sim.Id && s.Device.Id == simDevice.Device.Id))
            {
                ModelState.AddModelError(nameof(SimAndDevice), Messages.Duplicate);
                return(ValidationProblem(ModelState));
            }
            try
            {
                _userRepository.Create(simDevice);
            }
            catch (DbUpdateException)
            {
                return(Conflict());
                //throw;
            }
            return(CreatedAtAction("GetSimAndDevice", new { id = simDevice.Id }, simDevice));
        }
Exemplo n.º 14
0
        public void Case03()
        {
            var simDevice1 = new SimAndDevice() // 組織 : '自組織
            {
                Sim                    = _sim1,
                Device                 = _device1,
                IsolatedNw2Ip          = "127.0.0.1",
                AuthenticationDuration = 1,
                StartDate              = DateTime.Parse("2020-02-07"),
            };

            _context.Add(simDevice1);
            _context.SaveChanges();
            var(response, _, json) = Utils.Get(_client, $"{Url}/?page=30", "user1", "user1", 1, "domain01");  // ユーザー管理者
            var list = (JArray)json["results"];

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Empty(list);
        }
Exemplo n.º 15
0
        public void Case10()
        {
            for (int j = 1; j <= 2; j++)
            {
                for (int i = 1; i <= 25; i++)
                {
                    var simDeviceAuthenticationStateDone = new SimAndDeviceAuthenticated()
                    {
                        Expiration = DateTime.Now.AddHours(6.00)
                    };
                    var simDevice = new SimAndDevice() // 組織 : '自組織 認証済み:'フィルターに合致
                    {
                        Sim                       = _sim1,
                        Device                    = _device1,
                        IsolatedNw2Ip             = $"127.0.0.{i:00}",
                        AuthenticationDuration    = i,
                        StartDate                 = DateTime.Parse($"2020-{j:00}-{i:00}"),
                        SimAndDeviceAuthenticated = simDeviceAuthenticationStateDone
                    };
                    _context.AddRange(simDevice, simDeviceAuthenticationStateDone);
                }
            }
            _context.Add(new SimAndDevice() // 組織 : '自組織 認証済み:'フィルターに合致せず
            {
                Sim                    = _sim1,
                Device                 = _device1,
                IsolatedNw2Ip          = "127.0.0.1",
                AuthenticationDuration = 1,
                StartDate              = DateTime.Parse("2020-02-01")
            });
            _context.SaveChanges();
            var(response, _, json) = Utils.Get(_client, $"{Url}/?page=3&IsAuthenticationDone=True&sortBy=startDate&orderBy=asc", "user1", "user1", 1, "domain01");  // ユーザー管理者
            var list = (JArray)json["results"];

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.InRange(list.Count, 1, 20);
            Assert.Equal(50, (int)json["count"]);
            Assert.Equal("2020-02-16", list[0]["startDate"]);
            Assert.Equal("2020-02-17", list[1]["startDate"]); // 利用開始日ソート:'昇順
        }
        private SimAndDeviceAuthenticated CreateSimAndDeviceAuthenticated(SimAndDevice simAndDevice)
        {
            string startTime = _configuration.GetSection("Auth:ExpireHour").Value;
            var    simAndDeviceAuthenticated = simAndDevice.SimAndDeviceAuthenticated;

            if (simAndDeviceAuthenticated == null)
            {
                simAndDeviceAuthenticated = new SimAndDeviceAuthenticated
                {
                    Expiration = DateTime.Now.AddHours(double.Parse(startTime))
                };
                simAndDevice.SimAndDeviceAuthenticated = simAndDeviceAuthenticated;
                _authenticationRepository.Create(simAndDeviceAuthenticated);
            }
            else
            {
                simAndDeviceAuthenticated.Expiration =
                    DateTime.Now.AddHours(double.Parse(startTime));
                _authenticationRepository.Update(simAndDeviceAuthenticated);
            }
            return(simAndDeviceAuthenticated);
        }
Exemplo n.º 17
0
        public void Case03()
        {
            var simDeviceAuthenticationStateDone = new SimAndDeviceAuthenticated()
            {
                Expiration = DateTime.Now.AddHours(1.00)
            };
            var simDevice1 = new SimAndDevice() // 組織 : '他組織
            {
                Sim                       = _sim2,
                Device                    = _device1,
                IsolatedNw2Ip             = "127.0.0.1",
                AuthenticationDuration    = 1,
                StartDate                 = DateTime.Parse("2020-02-07"),
                EndDate                   = DateTime.Now.AddHours(6.00),
                SimAndDeviceAuthenticated = simDeviceAuthenticationStateDone
            };

            _context.Add(simDeviceAuthenticationStateDone);
            _context.Add(simDevice1);
            _context.SaveChanges();
            var(response, _, json) = Utils.Get(_client, $"{Url}/{simDevice1.Id}", "user1", "user1", 1, "domain01");  // ユーザー管理者
            Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
            Assert.NotNull(json["errors"]["Role"]);
        }
Exemplo n.º 18
0
        public InquiryMineTests(CustomWebApplicationFactory <JinCreek.Server.Admin.Startup> factory)
        {
            _client  = factory.CreateClient();
            _context = factory.Services.GetService <IServiceScopeFactory>().CreateScope().ServiceProvider.GetService <MainDbContext>();

            Utils.RemoveAllEntities(_context);

            _context.Add(_org1    = Utils.CreateOrganization(code: 1, name: "org1"));
            _context.Add(_org2    = Utils.CreateOrganization(code: 2, name: "org2"));
            _context.Add(_domain1 = new Domain {
                Id = Guid.NewGuid(), Name = "domain01", OrganizationCode = _org1.Code
            });
            _context.Add(_domain2 = new Domain {
                Id = Guid.NewGuid(), Name = "domain02", OrganizationCode = _org2.Code
            });
            _context.Add(_userGroup1 = new UserGroup {
                Id = Guid.NewGuid(), Name = "userGroup1", DomainId = _domain1.Id
            });
            _context.Add(_userGroup2 = new UserGroup {
                Id = Guid.NewGuid(), Name = "userGroup2", DomainId = _domain2.Id
            });
            _context.Add(_user0 = new SuperAdmin {
                AccountName = "user0", Password = Utils.HashPassword("user0")
            });                                                                                                      // スーパー管理者
            _context.Add(_user1 = new UserAdmin {
                AccountName = "user1", Password = Utils.HashPassword("user1"), DomainId = _domain1.Id
            });                                                                                                                             // ユーザー管理者
            _context.Add(_user2 = new GeneralUser()
            {
                AccountName = "user2", DomainId = _domain2.Id
            });
            _context.Add(_simGroup1 = new SimGroup
            {
                Id                      = Guid.NewGuid(),
                Name                    = "simGroup1",
                Organization            = _org1,
                Apn                     = "apn",
                AuthenticationServerIp  = "AuthServerIpAddress",
                IsolatedNw1IpPool       = "Nw1IpAddressPool",
                IsolatedNw1SecondaryDns = "Nw1SecondaryDns",
                IsolatedNw1IpRange      = "Nw1IpAddressRange",
                IsolatedNw1PrimaryDns   = "Nw1PrimaryDns",
                NasIp                   = "NasIpAddress",
                UserNameSuffix          = "UserNameSuffix",
                PrimaryDns              = "PrimaryDns",
                SecondaryDns            = "SecondaryDns"
            });
            _context.Add(_simGroup2 = new SimGroup {
                Id = Guid.NewGuid(), Name = "simGroup2", OrganizationCode = _org2.Code
            });
            _context.Add(_sim1 = new Sim {
                SimGroup = _simGroup1, Msisdn = "msisdn01", Imsi = "imsi01", IccId = "iccid01", UserName = "******", Password = "******"
            });
            _context.Add(_sim2 = new Sim {
                SimGroup = _simGroup1, Msisdn = "msisdn01", Imsi = "imsi01", IccId = "iccid01", UserName = "******", Password = "******"
            });                                                                                                                                                         //他組織
            _context.Add(_deviceGroup1 = new DeviceGroup {
                Id = Guid.NewGuid(), DomainId = _domain1.Id, Name = "deviceGroup1"
            });
            _context.Add(_device1 = new Device {
                Id = Guid.NewGuid(), DomainId = _domain1.Id, Name = "device1", ManagedNumber = "2", UseTpm = true, WindowsSignInListCacheDays = 1
            });
            _context.Add(_device1 = new Device {
                Id = Guid.NewGuid(), DomainId = _domain2.Id, Name = "device2", ManagedNumber = "2", UseTpm = true, WindowsSignInListCacheDays = 1
            });                                                                                                                                                                       //他組織
            _context.Add(_simDevice1 = new SimAndDevice {
                SimId = _sim1.Id, DeviceId = _device1.Id
            });
            _context.Add(_simDevice2 = new SimAndDevice {
                SimId = _sim2.Id, DeviceId = _device1.Id
            });                                                                                        // sim 他組織
            //_context.Add(_simDevice3 = new SimAndDevice { SimId = _sim1.Id, DeviceId = _device2.Id }); // 端末 他組織
            _context.Add(_multiFactor2 = new MultiFactor {
                Id = Guid.NewGuid(), SimAndDeviceId = _simDevice1.Id, EndUserId = _user2.Id
            });                                                                                                                            //User他組織
            _context.SaveChanges();
        }
Exemplo n.º 19
0
        public RegisterTests(CustomWebApplicationFactoryWithMariaDb <Startup> factory)
        {
            _client  = factory.CreateClient();
            _context = factory.Services.GetService <IServiceScopeFactory>().CreateScope().ServiceProvider.GetService <MainDbContext>();
            Utils.RemoveAllEntities(_context);

            _context.Add(_org1    = Utils.CreateOrganization(code: 1, name: "org1", startDate: DateTime.Parse("2020-01-14"), endDate: DateTime.Parse("2021-01-30")));
            _context.Add(_domain1 = new Domain {
                Id = Guid.NewGuid(), Name = "domain01", Organization = _org1
            });
            _context.Add(_userGroup1 = new UserGroup {
                Id = Guid.NewGuid(), Domain = _domain1, Name = "userGroup1"
            });
            _context.Add(_user1 = new SuperAdmin {
                AccountName = "user0", Name = "user0", Password = Utils.HashPassword("user0")
            });                                                                                                                      // スーパー管理者
            _context.Add(_user2 = new UserAdmin {
                AccountName = "user1", Name = "user1", Password = Utils.HashPassword("user1"), Domain = _domain1
            });                                                                                                                                        // ユーザー管理者
            _context.Add(_user3 = new GeneralUser {
                AccountName = "user2", Name = "user2", DomainId = _domain1.Id
            });
            _context.Add(new UserGroupEndUser()
            {
                EndUser = _user2, UserGroup = _userGroup1
            });
            _context.Add(new AvailablePeriod {
                EndUser = _user2, EndDate = DateTime.Parse("2021-03-01"), StartDate = DateTime.Parse("2020-02-10")
            });
            _context.Add(new AvailablePeriod {
                EndUser = _user3, EndDate = DateTime.Parse("2021-03-01"), StartDate = DateTime.Parse("2020-02-10")
            });
            _context.Add(_deviceGroup1 = new DeviceGroup {
                Id = Guid.NewGuid(), Name = "_deviceGroup1", Domain = _domain1
            });
            _context.Add(_lteModule1 = new LteModule {
                Name = "lte1", UseSoftwareRadioState = true, NwAdapterName = "abc"
            });
            _context.Add(_device1 = new Device()
            {
                LteModule     = _lteModule1,
                Domain        = _domain1,
                Name          = "device01",
                UseTpm        = true,
                ManagedNumber = "001",
                WindowsSignInListCacheDays = 1,
            });
            _context.Add(_simGroup1 = new SimGroup()
            {
                Id                      = Guid.NewGuid(),
                Name                    = "simGroup1",
                Organization            = _org1,
                Apn                     = "apn",
                AuthenticationServerIp  = "AuthServerIpAddress",
                IsolatedNw1IpPool       = "Nw1IpAddressPool",
                IsolatedNw1SecondaryDns = "Nw1SecondaryDns",
                IsolatedNw1IpRange      = "Nw1IpAddressRange",
                IsolatedNw1PrimaryDns   = "Nw1PrimaryDns",
                NasIp                   = "NasIpAddress",
                UserNameSuffix          = "UserNameSuffix",
                PrimaryDns              = "PrimaryDns",
                SecondaryDns            = "SecondaryDns"
            });
            _context.Add(_sim1 = new Sim() // 組織 : '自組織
            {
                Msisdn   = "1001",
                Imsi     = "1001",
                IccId    = "1001",
                UserName = "******",
                Password = "******",
                SimGroup = _simGroup1
            });
            _context.Add(_sim2 = new Sim() // 組織 : '自組織
            {
                Msisdn   = "1002",
                Imsi     = "1002",
                IccId    = "1002",
                UserName = "******",
                Password = "******",
                SimGroup = _simGroup1
            });
            _context.Add(_simAndDevice1 = new SimAndDevice()
            {
                Sim                    = _sim1,
                Device                 = _device1,
                IsolatedNw2Ip          = "127.0.0.1/18",
                AuthenticationDuration = 1,
                StartDate              = DateTime.Parse("2020-02-01"),
                EndDate                = DateTime.Parse("2021-02-01")
            });
            _context.SaveChanges();
        }
        private SimDeviceAuthenticationResponse CreateSimDeviceAuthenticationResponse(SimAndDeviceAuthenticated simAndDeviceAuthenticated, SimAndDevice simAndDevice, HashSet <string> canLogonUsers)
        {
            var simDeviceAuthenticationResponse = new SimDeviceAuthenticationResponse
            {
                AuthId                     = simAndDeviceAuthenticated.Id,
                CanLogonUsers              = canLogonUsers,
                AssignDeviceIpAddress      = simAndDevice.IsolatedNw2Ip,
                WindowsSignInListCacheDays = simAndDevice.Device.WindowsSignInListCacheDays,
                IsSoftwareRadioState       = simAndDevice.Device.LteModule?.UseSoftwareRadioState,
                AuthenticationDuration     = simAndDevice.AuthenticationDuration
            };

            if (simAndDevice.Device.OrganizationClientApp != null)
            {
                var clientInformation = new SimDeviceAuthenticationResponse.ClientInformation();
                clientInformation.Os = simAndDevice.Device.OrganizationClientApp?.ClientApp.ClientOs.Name;

                try
                {
                    clientInformation.Version = new Version(simAndDevice.Device.OrganizationClientApp?.ClientApp.Version);
                }
                catch (ArgumentException)
                {
                    _logger.LogWarning($"Invalid Version {simAndDevice.Device.OrganizationClientApp?.ClientApp.Version}");
                }

                simDeviceAuthenticationResponse.Client = clientInformation;
            }
            return(simDeviceAuthenticationResponse);
        }
Exemplo n.º 21
0
        public InquiryTests(CustomWebApplicationFactoryWithMariaDb <JinCreek.Server.Admin.Startup> factory)
        {
            _client  = factory.CreateClient();
            _context = factory.Services.GetService <IServiceScopeFactory>().CreateScope().ServiceProvider.GetService <MainDbContext>();

            Utils.RemoveAllEntities(_context);

            _context.Add(_org1    = Utils.CreateOrganization(code: 1, name: "org1"));
            _context.Add(_org2    = Utils.CreateOrganization(code: 2, name: "org2"));
            _context.Add(_domain1 = new Domain {
                Id = Guid.NewGuid(), Name = "domain01", OrganizationCode = _org1.Code
            });
            _context.Add(_domain2 = new Domain {
                Id = Guid.NewGuid(), Name = "domain02", OrganizationCode = _org2.Code
            });
            _context.Add(_userGroup1 = new UserGroup {
                Id = Guid.NewGuid(), Name = "userGroup1", DomainId = _domain1.Id
            });
            _context.Add(_userGroup2 = new UserGroup {
                Id = Guid.NewGuid(), Name = "userGroup2", DomainId = _domain2.Id
            });
            _context.Add(_user0 = new SuperAdmin {
                Name = "", AccountName = "user0", Password = Utils.HashPassword("user0")
            });                                                                                                                 // スーパー管理者
            _context.Add(_user1 = new UserAdmin()
            {
                Name = "", AccountName = "user1", Password = Utils.HashPassword("user1"), Domain = _domain1
            });                                                                                                                                     // ユーザー管理者
            _context.Add(_user2 = new GeneralUser()
            {
                Name = "", AccountName = "user2", DomainId = _domain1.Id
            });
            _context.Add(_user3 = new GeneralUser()
            {
                Name = "", AccountName = "user3", DomainId = _domain1.Id
            });
            _context.Add(_user4 = new GeneralUser()
            {
                Name = "", AccountName = "user4", DomainId = _domain2.Id
            });
            _context.Add(new AvailablePeriod()
            {
                EndUser = _user1, EndDate = DateTime.Parse("2021-03-01"), StartDate = DateTime.Parse("2020-02-10")
            });
            _context.Add(new AvailablePeriod()
            {
                EndUser = _user2, EndDate = DateTime.Parse("2021-03-01"), StartDate = DateTime.Parse("2020-02-10")
            });
            _context.Add(new AvailablePeriod()
            {
                EndUser = _user3, EndDate = DateTime.Parse("2021-03-01"), StartDate = DateTime.Parse("2020-02-10")
            });
            _context.Add(new AvailablePeriod()
            {
                EndUser = _user4, EndDate = DateTime.Parse("2021-03-01"), StartDate = DateTime.Parse("2020-02-10")
            });
            _context.Add(_userGroupEndUser = new UserGroupEndUser()
            {
                EndUser = _user2, UserGroup = _userGroup1
            });
            _context.Add(_simGroup1 = new SimGroup
            {
                Name                    = "simGroup1",
                Organization            = _org1,
                Apn                     = "apn",
                AuthenticationServerIp  = "AuthServerIpAddress",
                IsolatedNw1IpPool       = "Nw1IpAddressPool",
                IsolatedNw1SecondaryDns = "Nw1SecondaryDns",
                IsolatedNw1IpRange      = "Nw1IpAddressRange",
                IsolatedNw1PrimaryDns   = "Nw1PrimaryDns",
                NasIp                   = "NasIpAddress",
                UserNameSuffix          = "UserNameSuffix",
                PrimaryDns              = "PrimaryDns",
                SecondaryDns            = "SecondaryDns"
            });
            _context.Add(_sim1 = new Sim {
                SimGroup = _simGroup1, Msisdn = "msisdn01", Imsi = "imsi01", IccId = "iccid01", UserName = "******", Password = "******"
            });
            _context.Add(_sim2 = new Sim {
                SimGroup = _simGroup1, Msisdn = "msisdn02", Imsi = "imsi02", IccId = "iccid02", UserName = "******", Password = "******"
            });
            _context.Add(_deviceGroup1 = new DeviceGroup {
                DomainId = _domain1.Id, Name = "deviceGroup1"
            });
            _context.Add(_device1 = new Device
            {
                LteModule     = _lte1,
                Domain        = _domain1,
                Name          = "device01",
                UseTpm        = true,
                ManagedNumber = "001",
                ProductName   = "",
                SerialNumber  = "",
                WindowsSignInListCacheDays = 1,
                StartDate = DateTime.Parse("2020-02-07"),
                EndDate   = DateTime.Parse("2021-02-01")
            });
            _context.Add(_device2 = new Device
            {
                LteModule     = _lte1,
                Domain        = _domain1,
                Name          = "device02",
                UseTpm        = true,
                ManagedNumber = "002",
                ProductName   = "",
                SerialNumber  = "",
                WindowsSignInListCacheDays = 1,
                StartDate = DateTime.Parse("2020-02-07"),
                EndDate   = DateTime.Parse("2021-02-01")
            });
            _context.Add(_device3 = new Device
            {
                LteModule     = _lte1,
                Domain        = _domain2,
                Name          = "device02",
                UseTpm        = true,
                ManagedNumber = "002",
                ProductName   = "",
                SerialNumber  = "",
                WindowsSignInListCacheDays = 1,
                StartDate = DateTime.Parse("2020-02-07"),
                EndDate   = DateTime.Parse("2021-02-01")
            });
            _context.Add(_simDevice1 = new SimAndDevice
            {
                SimId                  = _sim1.Id,
                DeviceId               = _device1.Id,
                IsolatedNw2Ip          = "127.0.0.1",
                AuthenticationDuration = 1,
                StartDate              = DateTime.Parse("2020-02-07"),
                EndDate                = DateTime.Parse("2020-03-07"),
            });
            _context.Add(_simDevice2 = new SimAndDevice
            {
                SimId                  = _sim2.Id,
                DeviceId               = _device1.Id,
                IsolatedNw2Ip          = "127.0.0.1",
                AuthenticationDuration = 1,
                StartDate              = DateTime.Parse("2020-02-07"),
                EndDate                = DateTime.Parse("2020-03-07"),
            });
            _context.Add(_simDevice3 = new SimAndDevice
            {
                SimId                  = _sim1.Id,
                DeviceId               = _device2.Id,
                IsolatedNw2Ip          = "127.0.0.1",
                AuthenticationDuration = 1,
                StartDate              = DateTime.Parse("2020-02-07"),
                EndDate                = DateTime.Parse("2020-03-07"),
            });
            _context.Add(_simDevice4 = new SimAndDevice
            {
                SimId                  = _sim2.Id,
                DeviceId               = _device2.Id,
                IsolatedNw2Ip          = "127.0.0.1",
                AuthenticationDuration = 1,
                StartDate              = DateTime.Parse("2020-02-07"),
                EndDate                = DateTime.Parse("2020-03-07"),
            });
            _context.Add(_multiFactor1 = new MultiFactor
            {
                Id             = Guid.NewGuid(),
                SimAndDeviceId = _simDevice1.Id,
                EndUserId      = _user2.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Parse("2020-02-01"),
            });
            _context.Add(_multiFactor2 = new MultiFactor
            {
                Id             = Guid.NewGuid(),
                SimAndDeviceId = _simDevice2.Id,
                EndUserId      = _user2.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Parse("2020-02-01"),
            });
            _context.Add(_multiFactor3 = new MultiFactor
            {
                Id             = Guid.NewGuid(),
                SimAndDeviceId = _simDevice3.Id,
                EndUserId      = _user2.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Parse("2020-02-01"),
            });
            _context.Add(_multiFactor4 = new MultiFactor
            {
                Id             = Guid.NewGuid(),
                SimAndDeviceId = _simDevice4.Id,
                EndUserId      = _user2.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Parse("2020-02-01"),
            });
            _context.Add(_multiFactor5 = new MultiFactor
            {
                Id             = Guid.NewGuid(),
                SimAndDeviceId = _simDevice1.Id,
                EndUserId      = _user3.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Parse("2020-02-01"),
            });
            _context.Add(_multiFactor6 = new MultiFactor
            {
                Id             = Guid.NewGuid(),
                SimAndDeviceId = _simDevice2.Id,
                EndUserId      = _user3.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Parse("2020-02-01"),
            });
            _context.Add(_multiFactor7 = new MultiFactor
            {
                Id             = Guid.NewGuid(),
                SimAndDeviceId = _simDevice3.Id,
                EndUserId      = _user3.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Parse("2020-02-01"),
            });
            _context.Add(_multiFactor8 = new MultiFactor
            {
                Id             = Guid.NewGuid(),
                SimAndDeviceId = _simDevice4.Id,
                EndUserId      = _user3.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Parse("2020-02-01"),
            });
            _context.Add(_multiFactor9 = new MultiFactor
            {
                Id             = Guid.NewGuid(),
                SimAndDeviceId = _simDevice1.Id,
                EndUserId      = _user4.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Parse("2020-02-01"),
            });
            _context.Add(_multiFactor10 = new MultiFactor
            {
                Id             = Guid.NewGuid(),
                SimAndDeviceId = _simDevice2.Id,
                EndUserId      = _user4.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Parse("2020-02-01"),
            });
            _context.Add(_multiFactor11 = new MultiFactor
            {
                Id             = Guid.NewGuid(),
                SimAndDeviceId = _simDevice3.Id,
                EndUserId      = _user4.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Parse("2020-02-01"),
            });
            _context.Add(_multiFactor12 = new MultiFactor
            {
                Id             = Guid.NewGuid(),
                SimAndDeviceId = _simDevice4.Id,
                EndUserId      = _user4.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Parse("2020-02-01"),
            });
            _context.Add(new MultiFactorAuthenticated()
            {
                Expiration = DateTime.Now.AddHours(1.00), MultiFactor = _multiFactor1
            });
            _context.Add(new MultiFactorAuthenticated()
            {
                Expiration = DateTime.Now.AddHours(1.00), MultiFactor = _multiFactor2
            });
            _context.Add(new MultiFactorAuthenticated()
            {
                Expiration = DateTime.Now.AddHours(1.00), MultiFactor = _multiFactor3
            });
            _context.Add(new MultiFactorAuthenticated()
            {
                Expiration = DateTime.Now.AddHours(1.00), MultiFactor = _multiFactor4
            });
            _context.Add(new MultiFactorAuthenticated()
            {
                Expiration = DateTime.Now.AddHours(1.00), MultiFactor = _multiFactor5
            });
            _context.Add(new MultiFactorAuthenticated()
            {
                Expiration = DateTime.Now.AddHours(1.00), MultiFactor = _multiFactor6
            });
            _context.Add(new MultiFactorAuthenticated()
            {
                Expiration = DateTime.Now.AddHours(1.00), MultiFactor = _multiFactor7
            });
            _context.Add(new MultiFactorAuthenticated()
            {
                Expiration = DateTime.Now.AddHours(1.00), MultiFactor = _multiFactor8
            });
            _context.Add(new MultiFactorAuthenticated()
            {
                Expiration = DateTime.Now.AddHours(1.00), MultiFactor = _multiFactor9
            });
            _context.Add(new MultiFactorAuthenticated()
            {
                Expiration = DateTime.Now.AddHours(1.00), MultiFactor = _multiFactor10
            });
            _context.Add(new MultiFactorAuthenticated()
            {
                Expiration = DateTime.Now.AddHours(1.00), MultiFactor = _multiFactor11
            });
            _context.Add(new MultiFactorAuthenticated()
            {
                Expiration = DateTime.Now.AddHours(1.00), MultiFactor = _multiFactor12
            });
            _context.SaveChanges();
        }
Exemplo n.º 22
0
        private void SetDataDeviceGroup06()
        {
            //DeviceGroup-6
            var deviceGroup = new DeviceGroup()
            {
                Domain     = Domain,
                Name       = "deviceGroup01",
                AdObjectId = Guid.Parse("435cd502-5a65-4649-8a39-1e53294304f8") //削除
            };

            Device1 = new Device() // Devive-7
            {
                Domain = Domain,
                Name   = "device01",
                UseTpm = true,
                WindowsSignInListCacheDays = 1,
                StartDate             = DateTime.Parse("2020-03-01"),
                ManagedNumber         = "",
                SerialNumber          = "",
                ProductName           = "",
                AdObjectId            = Guid.NewGuid(),
                OrganizationClientApp = OrganizationClientApp,
                LteModule             = new LteModule()
                {
                    Name                  = "lte01",
                    NwAdapterName         = "",
                    UseSoftwareRadioState = true
                },
                DeviceGroupDevices = new HashSet <DeviceGroupDevice>()
                {
                    new DeviceGroupDevice()
                    {
                        DeviceGroup = deviceGroup
                    }
                },
                EndDate = null // EndDate : 不在
            };
            SimAndDevice1 = new SimAndDevice()
            {
                Device                 = Device1,
                Sim                    = Sim1,
                IsolatedNw2Ip          = "",
                AuthenticationDuration = 1,
                StartDate              = DateTime.Parse("2020-03-01"),
                EndDate                = DateTime.Parse("2021-03-02") // '存在(実行日以外)
            };
            MainDbContext.SimAndDevice.Add(new SimAndDevice()
            {
                Device = Device1,
                Sim    = new Sim()
                {
                    Msisdn   = "11111111112",
                    Imsi     = "1111111112",
                    IccId    = "1111111112",
                    UserName = "******",
                    Password = "******",
                    SimGroup = SimGroup1
                },
                IsolatedNw2Ip          = "",
                AuthenticationDuration = 1,
                StartDate = DateTime.Parse("2020-03-01") // endDate:不在
            });
            MainDbContext.AddRange(deviceGroup, Device1, SimAndDevice1);
        }
Exemplo n.º 23
0
        public DeleteMineTests(CustomWebApplicationFactoryWithMariaDb <Admin.Startup> factory)
        {
            _client  = factory.CreateClient();
            _context = factory.Services.GetService <IServiceScopeFactory>().CreateScope().ServiceProvider.GetService <MainDbContext>();
            Utils.RemoveAllEntities(_context);

            _context.Add(_org1    = Utils.CreateOrganization(code: 1, name: "org1"));
            _context.Add(_org2    = Utils.CreateOrganization(code: 2, name: "org2"));
            _context.Add(_domain1 = new Domain {
                Id = Guid.NewGuid(), Name = "domain01", Organization = _org1
            });
            _context.Add(_domain2 = new Domain {
                Id = Guid.NewGuid(), Name = "domain02", Organization = _org2
            });
            _context.Add(_userGroup1 = new UserGroup {
                Id = Guid.NewGuid(), Name = "userGroup1", Domain = _domain1
            });
            _context.Add(_userGroup2 = new UserGroup {
                Id = Guid.NewGuid(), Name = "userGroup2", Domain = _domain2
            });

            _context.Add(_user1 = new SuperAdmin {
                AccountName = "user0", Name = "user0", Password = Utils.HashPassword("user0")
            });                                                                                                                      // スーパー管理者
            _context.Add(_user2 = new UserAdmin {
                AccountName = "user1", Name = "user1", Password = Utils.HashPassword("user1"), Domain = _domain1
            });                                                                                                                                        // ユーザー管理者
            _context.Add(_user3 = new GeneralUser {
                AccountName = "user2", Name = "user2", DomainId = _domain1.Id
            });
            _context.Add(_user4 = new GeneralUser {
                AccountName = "user4", Name = "user4", DomainId = _domain2.Id
            });

            _context.Add(_simGroup1 = Utils.CreateSimGroup(name: "simGroup1", organization: _org1, isolatedNw1IpPool: "IsolatedNw1IpPool"));
            _context.Add(_simGroup2 = Utils.CreateSimGroup(name: "simGroup2", organization: _org2, isolatedNw1IpPool: "IsolatedNw1IpPool"));
            _context.Add(_sim1      = new Sim() // 組織 : '自組織
            {
                Msisdn   = "msisdn01",
                Imsi     = "imsi01",
                IccId    = "iccid01",
                UserName = "******",
                Password = "******",
                SimGroup = _simGroup1
            });
            _context.Add(_sim2 = new Sim() // 組織 : '他組織
            {
                Msisdn   = "1002",
                Imsi     = "1002",
                IccId    = "1002",
                UserName = "******",
                Password = "******",
                SimGroup = _simGroup2
            });
            _context.Add(_device1 = new Device()
            {
                LteModule     = null,
                Domain        = _domain1,
                Name          = "device01",
                UseTpm        = true,
                ManagedNumber = "001",
                WindowsSignInListCacheDays = 1,
            });
            _context.Add(_simDevice1 = new SimAndDevice()
            {
                Sim                    = _sim1,
                Device                 = _device1,
                IsolatedNw2Ip          = "127.0.0.1/18",
                AuthenticationDuration = 1,
                StartDate              = DateTime.Parse("2020-02-01"),
                EndDate                = DateTime.Parse("2020-02-09")
            });
            _context.Add(_multiFactor1 = new MultiFactor
            {
                SimAndDeviceId = _simDevice1.Id,
                EndUserId      = _user3.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Now,
                EndDate        = DateTime.Now
            });
            _context.Add(_multiFactor2 = new MultiFactor // 他組織
            {
                SimAndDeviceId = _simDevice1.Id,
                EndUserId      = _user4.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Now,
                EndDate        = DateTime.Now
            });
            _context.SaveChanges();
        }
Exemplo n.º 24
0
        /// <summary>
        /// CSVインポート
        /// </summary>
        /// <param name="csv"></param>
        /// <param name="endUser"></param>
        /// <returns></returns>
        private ActionResult <IEnumerable <SimAndDevice> > ImportCsv(TextReader csv, EndUser endUser = null)
        {
            // 1. 型変換エラーがあればここで終了する:
            var records = Utils.ParseCsv <CsvRecord, CsvRecordMap>(csv, ModelState);

            if (!ModelState.IsValid)
            {
                return(ValidationProblem(ModelState));
            }

            // 2. バリデーションエラーがあればここで終了する:
            Utils.TryValidateCsvRecords(records, ModelState);
            if (!ModelState.IsValid)
            {
                return(ValidationProblem(ModelState));
            }

            var simDevices = new List <SimAndDevice>();

            using (var transaction = _context.Database.BeginTransaction())
            {
                foreach (var record in records)
                {
                    var sim    = _userRepository.GetSim((Guid)record.SimId);
                    var device = _userRepository.GetDevice((Guid)record.DeviceId);
                    if (record.StartDate < device.StartDate || record.StartDate > device.EndDate)
                    {
                        ModelState.AddModelError(nameof(record.StartDate), Messages.OutOfDate);
                    }
                    if (record.EndDate < device.StartDate || record.EndDate > device.EndDate)
                    {
                        ModelState.AddModelError(nameof(record.EndDate), Messages.OutOfDate);
                    }
                    if (!ModelState.IsValid)
                    {
                        return(ValidationProblem(ModelState));
                    }

                    var simDevice = _context.SimAndDevice
                                    .Include(s => s.Sim)
                                    .Include(s => s.Device)
                                    .Include(s => s.Sim.SimGroup)
                                    .Include(s => s.Sim.SimGroup.Organization)
                                    .SingleOrDefault(s => s.SimId == sim.Id && s.DeviceId == device.Id);
                    if (simDevice == null) // simDeviceはない そしてDeleteはDかdのない 登録
                    {
                        var simDevice1 = new SimAndDevice()
                        {
                            Sim    = sim,
                            Device = device,
                            AuthenticationDuration = (int)record.AuthenticationDuration,
                            IsolatedNw2Ip          = record.IsolatedNw2Ip,
                            EndDate   = record.EndDate,
                            StartDate = (DateTime)record.StartDate
                        };
                        _userRepository.Create(simDevice1);
                        simDevices.Add(simDevice1);
                        continue;
                    }
                    if (endUser != null && simDevice.Sim.SimGroup.Organization.Code != endUser.Domain.Organization.Code)
                    {
                        ModelState.AddModelError("Role", Messages.InvalidRole);
                        return(ValidationProblem(modelStateDictionary: ModelState, statusCode: StatusCodes.Status403Forbidden));
                    }
                    if ("d".Equals(record.Delete) || "D".Equals(record.Delete)) // Dかdか そしてsimDeviceはあり は削除
                    {
                        if (_context.SimAndDeviceAuthenticated.Any(s => s.SimAndDeviceId == simDevice.Id))
                        {
                            ModelState.AddModelError(nameof(SimAndDeviceAuthenticated), Messages.ChildEntityExists);
                            return(ValidationProblem(ModelState));
                        }
                        if (_context.MultiFactor.Any(f => f.SimAndDeviceId == simDevice.Id))
                        {
                            ModelState.AddModelError("FactorCombination", Messages.ChildEntityExists);
                            return(ValidationProblem(ModelState));
                        }
                        if (_context.MultiFactorAuthenticationFailureLog.Any(f => f.SimAndDevice.Id == simDevice.Id))
                        {
                            ModelState.AddModelError("MultiFactorAuthenticationFailure", Messages.ChildEntityExists);
                            return(ValidationProblem(ModelState));
                        }
                        if (_context.SimAndDeviceAuthenticationSuccessLog.Any(f => f.SimAndDevice.Id == simDevice.Id))
                        {
                            ModelState.AddModelError("SimAndDeviceAuthenticationSuccess", Messages.ChildEntityExists);
                            return(ValidationProblem(ModelState));
                        }
                        _userRepository.RemoveSimAndDevice(simDevice.Id);
                        simDevices.Add(simDevice);
                        continue;
                    }

                    simDevice.IsolatedNw2Ip          = record.IsolatedNw2Ip;
                    simDevice.StartDate              = (DateTime)record.StartDate;
                    simDevice.EndDate                = record.EndDate;
                    simDevice.AuthenticationDuration = (int)record.AuthenticationDuration;
                    _userRepository.Update(simDevice);
                    simDevices.Add(simDevice);
                }

                transaction.Commit();
            }
            return(Ok(simDevices));
        }
Exemplo n.º 25
0
        public RegisterMineTests(CustomWebApplicationFactoryWithMariaDb <Startup> factory)
        {
            _client  = factory.CreateClient();
            _context = factory.Services.GetService <IServiceScopeFactory>().CreateScope().ServiceProvider.GetService <MainDbContext>();
            Utils.RemoveAllEntities(_context);

            _context.Add(_org1    = Utils.CreateOrganization(code: 1, name: "org1", startDate: DateTime.Parse("2020-01-14"), endDate: DateTime.Parse("2021-01-30")));
            _context.Add(_org2    = Utils.CreateOrganization(code: 2, name: "org2", startDate: DateTime.Parse("2020-01-14"), endDate: DateTime.Parse("2021-01-30")));
            _context.Add(_domain1 = new Domain {
                Id = Guid.NewGuid(), Name = "domain01", Organization = _org1
            });
            _context.Add(_domain2 = new Domain {
                Id = Guid.NewGuid(), Name = "domain02", Organization = _org2
            });
            _context.Add(_userGroup1 = new UserGroup {
                Id = Guid.NewGuid(), Domain = _domain1, Name = "userGroup1"
            });
            _context.Add(_user1 = new SuperAdmin {
                AccountName = "user0", Name = "user0", Password = Utils.HashPassword("user0")
            });                                                                                                                     // スーパー管理者
            _context.Add(_user2 = new UserAdmin {
                AccountName = "user1", Name = "user1", Password = Utils.HashPassword("user1"), Domain = _domain1
            });                                                                                                                                       // ユーザー管理者
            _context.Add(_user3 = new GeneralUser {
                AccountName = "user2", Name = "user2", Domain = _domain1
            });
            _context.Add(new UserGroupEndUser {
                EndUser = _user2, UserGroup = _userGroup1
            });
            _context.Add(new AvailablePeriod {
                EndUser = _user2, EndDate = DateTime.Parse("2021-03-01"), StartDate = DateTime.Parse("2020-02-10")
            });
            _context.Add(new AvailablePeriod {
                EndUser = _user3, EndDate = DateTime.Parse("2021-03-01"), StartDate = DateTime.Parse("2020-02-10")
            });
            _context.Add(_user4 = new GeneralUser {
                AccountName = "user4", Name = "user4", Domain = _domain2
            });
            _context.Add(_deviceGroup1 = new DeviceGroup {
                Id = Guid.NewGuid(), Name = "_deviceGroup1", Domain = _domain1
            });
            _context.Add(_lteModule1 = new LteModule {
                Name = "lte1", UseSoftwareRadioState = true, NwAdapterName = "abc"
            });
            _context.Add(_device1 = new Device
            {
                LteModule     = _lteModule1,
                Domain        = _domain1,
                Name          = "device01",
                UseTpm        = true,
                ManagedNumber = "001",
                WindowsSignInListCacheDays = 1,
            });
            _context.Add(_device2 = new Device() // 他組織
            {
                LteModule     = _lteModule1,
                Domain        = _domain2,
                Name          = "device02",
                UseTpm        = true,
                ManagedNumber = "001",
                WindowsSignInListCacheDays = 1,
            });

            _context.Add(_simGroup1 = Utils.CreateSimGroup(organization: _org1, name: "simGroup1", isolatedNw1IpPool: "Nw1IpAddressPool"));
            _context.Add(_simGroup2 = Utils.CreateSimGroup(organization: _org2, name: "simGroup2", isolatedNw1IpPool: "Nw1IpAddressPool"));
            _context.Add(_sim1      = new Sim() // 組織 : '自組織
            {
                Msisdn   = "1001",
                Imsi     = "1001",
                IccId    = "1001",
                UserName = "******",
                Password = "******",
                SimGroup = _simGroup1
            });
            _context.Add(_sim2 = new Sim() // 組織 : '他組織
            {
                Msisdn   = "1002",
                Imsi     = "1002",
                IccId    = "1002",
                UserName = "******",
                Password = "******",
                SimGroup = _simGroup2
            });
            _context.Add(_simAndDevice1 = Utils.CreateSimAndDevice(sim: _sim1, device: _device1, startDate: DateTime.Parse("2020-02-01"), endDate: DateTime.Parse("2021-02-01")));
            _context.Add(_simAndDevice2 = Utils.CreateSimAndDevice(sim: _sim2, device: _device1)); // sim 他組織
            _context.Add(_simAndDevice3 = Utils.CreateSimAndDevice(sim: _sim1, device: _device2)); // 端末 他組織
            _context.SaveChanges();
        }
Exemplo n.º 26
0
        public ListingTests(CustomWebApplicationFactory <JinCreek.Server.Admin.Startup> factory)
        {
            _client  = factory.CreateClient();
            _context = factory.Services.GetService <IServiceScopeFactory>().CreateScope().ServiceProvider.GetService <MainDbContext>();

            Utils.RemoveAllEntities(_context);

            _context.Add(_org1    = Utils.CreateOrganization(code: 1, name: "org1"));
            _context.Add(_org2    = Utils.CreateOrganization(code: 2, name: "org2"));
            _context.Add(_domain1 = new Domain {
                Id = Guid.NewGuid(), Name = "domain01", Organization = _org1
            });
            _context.Add(_domain2 = new Domain {
                Id = Guid.NewGuid(), Name = "domain02", Organization = _org2
            });
            _context.Add(_user1 = new SuperAdmin {
                AccountName = "user0", Password = Utils.HashPassword("user0")
            });                                                                                                      // スーパー管理者
            _context.Add(_user2 = new UserAdmin()
            {
                AccountName = "user1", Password = Utils.HashPassword("user1"), Domain = _domain1
            });                                                                                                                          // ユーザー管理者
            _context.Add(_user3 = new GeneralUser()
            {
                AccountName = "user3", DomainId = _domain1.Id
            });
            _context.Add(_user3a = new GeneralUser()
            {
                AccountName = "user3a", DomainId = _domain1.Id
            });
            _context.Add(_user4 = new GeneralUser()
            {
                AccountName = "user4", DomainId = _domain2.Id
            });
            _context.Add(_deviceGroup1 = new DeviceGroup()
            {
                Id = Guid.NewGuid(), Name = "_deviceGroup1", Domain = _domain1
            });
            _context.Add(_lte1 = new LteModule()
            {
                Name = "lte1", UseSoftwareRadioState = true, NwAdapterName = "abc"
            });
            _context.Add(_simGroup1 = new SimGroup()
            {
                Id                      = Guid.NewGuid(),
                Name                    = "simGroup1",
                Organization            = _org1,
                Apn                     = "apn",
                AuthenticationServerIp  = "AuthServerIpAddress",
                IsolatedNw1IpPool       = "Nw1IpAddressPool",
                IsolatedNw1SecondaryDns = "Nw1SecondaryDns",
                IsolatedNw1IpRange      = "Nw1IpAddressRange",
                IsolatedNw1PrimaryDns   = "Nw1PrimaryDns",
                NasIp                   = "NasIpAddress",
                UserNameSuffix          = "UserNameSuffix",
                PrimaryDns              = "PrimaryDns",
                SecondaryDns            = "SecondaryDns"
            });
            _context.Add(_simGroup2 = new SimGroup
            {
                Id = Guid.NewGuid(), Name = "simGroup2", Organization = _org2, IsolatedNw1IpPool = ""
            });
            _context.Add(_sim1 = new Sim() // 組織 : '自組織
            {
                Msisdn   = "msisdn01",
                Imsi     = "imsi01",
                IccId    = "iccid01",
                UserName = "******",
                Password = "******",
                SimGroup = _simGroup1
            });
            _context.Add(_sim1a = new Sim() // 組織 : '自組織
            {
                Msisdn   = "msisdn01a",
                Imsi     = "imsi01a",
                IccId    = "iccid01a",
                UserName = "******",
                Password = "******",
                SimGroup = _simGroup1
            });
            _context.Add(_sim2 = new Sim() // 組織 : '他組織
            {
                Msisdn   = "msisdn02",
                Imsi     = "imsi02",
                IccId    = "iccid02",
                UserName = "******",
                Password = "******",
                SimGroup = _simGroup2
            });
            _context.Add(_device1 = new Device()
            {
                LteModule     = _lte1,
                Domain        = _domain1,
                Name          = "device01",
                UseTpm        = true,
                ManagedNumber = "001",
                WindowsSignInListCacheDays = 1,
            });
            _context.Add(_device1a = new Device()
            {
                LteModule     = _lte1,
                Domain        = _domain1,
                Name          = "device01a",
                UseTpm        = true,
                ManagedNumber = "001",
                WindowsSignInListCacheDays = 1,
            });
            _context.Add(_device2 = new Device()// 端末 他組織
            {
                LteModule     = _lte1,
                Domain        = _domain2,
                Name          = "device02",
                UseTpm        = true,
                ManagedNumber = "001",
                WindowsSignInListCacheDays = 1,
            });
            _context.Add(_simDevice1 = new SimAndDevice {
                SimId = _sim1.Id, DeviceId = _device1.Id
            });
            _context.Add(_simDevice1a = new SimAndDevice {
                SimId = _sim1a.Id, DeviceId = _device1.Id
            });
            _context.Add(_simDevice1b = new SimAndDevice {
                SimId = _sim1a.Id, DeviceId = _device1a.Id
            });
            _context.Add(_simDevice2 = new SimAndDevice {
                SimId = _sim2.Id, DeviceId = _device1.Id
            });                                                                                        // sim 他組織
            _context.Add(_simDevice3 = new SimAndDevice {
                SimId = _sim1.Id, DeviceId = _device2.Id
            });                                                                                        // 端末 他組織
            _context.SaveChanges();
        }
Exemplo n.º 27
0
        public UpdateTests(CustomWebApplicationFactory <JinCreek.Server.Admin.Startup> factory)
        {
            _client  = factory.CreateClient();
            _context = factory.Services.GetService <IServiceScopeFactory>().CreateScope().ServiceProvider.GetService <MainDbContext>();

            Utils.RemoveAllEntities(_context);

            _context.Add(_org1    = Utils.CreateOrganization(code: 1, name: "org1"));
            _context.Add(_org2    = Utils.CreateOrganization(code: 2, name: "org2"));
            _context.Add(_domain1 = new Domain {
                Id = Guid.NewGuid(), Name = "domain01", Organization = _org1
            });
            _context.Add(_domain2 = new Domain {
                Id = Guid.NewGuid(), Name = "domain02", Organization = _org2
            });
            _context.Add(_userGroup1 = new UserGroup {
                Id = Guid.NewGuid(), Name = "userGroup1", Domain = _domain1
            });
            _context.Add(_userGroup2 = new UserGroup {
                Id = Guid.NewGuid(), Name = "userGroup2", Domain = _domain2
            });

            _context.Add(_user1 = new SuperAdmin {
                AccountName = "user0", Password = Utils.HashPassword("user0")
            });                                                                                                      // スーパー管理者
            _context.Add(_user2 = new UserAdmin()
            {
                AccountName = "user1", Password = Utils.HashPassword("user1"), Domain = _domain1
            });                                                                                                                          // ユーザー管理者
            _context.Add(_user3 = new GeneralUser()
            {
                AccountName = "user2", DomainId = _domain1.Id
            });
            _context.Add(_availablePeriod = new AvailablePeriod()
            {
                EndUser = _user2, EndDate = DateTime.Parse("2021-03-01"), StartDate = DateTime.Parse("2020-02-10")
            });
            _context.Add(_availablePeriod = new AvailablePeriod()
            {
                EndUser = _user3, EndDate = DateTime.Parse("2021-03-01"), StartDate = DateTime.Parse("2020-02-10")
            });
            _context.Add(_simGroup1 = new SimGroup()
            {
                Id                      = Guid.NewGuid(),
                Name                    = "simGroup1",
                Organization            = _org1,
                Apn                     = "apn",
                AuthenticationServerIp  = "AuthenticationServerIp",
                IsolatedNw1IpPool       = "IsolatedNw1IpPool",
                IsolatedNw1SecondaryDns = "IsolatedNw1SecondaryDns",
                IsolatedNw1IpRange      = "IsolatedNw1IpRange",
                IsolatedNw1PrimaryDns   = "IsolatedNw1PrimaryDns",
                NasIp                   = "NasIp",
                PrimaryDns              = "PrimaryDns",
                SecondaryDns            = "SecondaryDns"
            });
            _context.Add(_simGroup2 = new SimGroup
            {
                Id = Guid.NewGuid(), Name = "simGroup2", Organization = _org2, IsolatedNw1IpPool = ""
            });
            _context.Add(_sim1 = new Sim() // 組織 : '自組織
            {
                Msisdn   = "msisdn01",
                Imsi     = "imsi01",
                IccId    = "iccid01",
                UserName = "******",
                Password = "******",
                SimGroup = _simGroup1
            });
            _context.Add(_device1 = new Device()
            {
                LteModule     = null,
                Domain        = _domain1,
                Name          = "device01",
                UseTpm        = true,
                ManagedNumber = "001",
                WindowsSignInListCacheDays = 1,
            });
            _context.Add(_simDevice1 = new SimAndDevice()
            {
                Sim                    = _sim1,
                Device                 = _device1,
                IsolatedNw2Ip          = "127.0.0.1/18",
                AuthenticationDuration = 1,
                StartDate              = DateTime.Parse("2020-02-01"),
                EndDate                = DateTime.Parse("2021-02-01")
            });
            _context.Add(_multiFactor1 = new MultiFactor
            {
                SimAndDeviceId = _simDevice1.Id,
                EndUserId      = _user3.Id,
                ClosedNwIp     = "127.0.0.1",
                StartDate      = DateTime.Now,
                EndDate        = DateTime.Now
            });
            _context.SaveChanges();
        }