コード例 #1
0
        public async Task UnknownUser()
        {
            BesteUser besteUser = new BesteUser();
            User      user      = new User
            {
                Username = "******",
                Password = "******"
            };
            BesteUserAuthentificationResponse authResponse = await besteUser.Authenticate(JsonConvert.SerializeObject(user, Formatting.None, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            }));

            ValiateResponse(authResponse, BesteUserAuthentificationResult.USER_UNKNOWN);

            ModifyUserResponse response = await besteUser.EditUser(JsonConvert.SerializeObject(user, Formatting.None, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            }));

            ValiateResponse(response, ModifyUserResult.USER_UNKNOWN);

            response = await besteUser.ChangePasswordByUser(JsonConvert.SerializeObject(user, Formatting.None, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            }));

            ValiateResponse(response, ModifyUserResult.USER_UNKNOWN);

            response = await besteUser.DeleteUser(JsonConvert.SerializeObject(user, Formatting.None, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            }));

            ValiateResponse(response, ModifyUserResult.USER_UNKNOWN);
        }
コード例 #2
0
        public async Task WrongPassword()
        {
            ClientWebSocket  webSocket        = new ClientWebSocket();
            WebSocketHandler webSocketHandler = new WebSocketHandler(webSocket);
            await webSocket.ConnectAsync(new Uri("ws://localhost:80/ws"), CancellationToken.None);

            byte[] buffer = new byte[1024 * 4];
            await webSocketHandler.ExtractCompleteMessage(buffer, 60);

            if (webSocketHandler.ReceivedCommand.CommandName != "Connected")
            {
                Assert.Fail();
            }

            User user = new User
            {
                Username = "******",
                Password = "******"
            };
            Command command = new Command("Login", user);
            await TestHelper.ExecuteCommandAndAwaitResponse(webSocket, webSocketHandler, command);

            BesteUserAuthentificationResponse authResponse = JsonConvert.DeserializeObject <BesteUserAuthentificationResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());

            TestHelper.ValiateResponse(authResponse, BesteUserAuthentificationResult.WRONG_PASSWORD);
        }
コード例 #3
0
        public void RightViolation()
        {
            // The checking of rights must be done in the application which uses the Module.User
            // This test checks for the result code existing

            BesteUserAuthentificationResponse authResponse = new BesteUserAuthentificationResponse(BesteUserAuthentificationResult.RIGHT_VIOLATION, null);

            ValiateResponse(authResponse, BesteUserAuthentificationResult.RIGHT_VIOLATION);

            ModifyUserResponse response = new ModifyUserResponse(ModifyUserResult.RIGHT_VIOLATION, null, null, null);

            ValiateResponse(response, ModifyUserResult.RIGHT_VIOLATION);
        }
コード例 #4
0
        public async Task WrongParameters()
        {
            BesteUser besteUser = new BesteUser();
            User      user      = new User
            {
                Username = "",
                Password = ""
            };
            BesteUserAuthentificationResponse authResponse = await besteUser.Authenticate(JsonConvert.SerializeObject(user, Formatting.None, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            }));

            ValiateResponse(authResponse, BesteUserAuthentificationResult.WRONG_PARAMETER);
        }
コード例 #5
0
        public async Task CreateUserAndLogin()
        {
            BesteUser besteUser = new BesteUser();

            User user = new User
            {
                Username  = "******",
                Lastname  = "Lastname",
                Firstname = "Firstname",
                Email     = "Email",
                Password  = "******"
            };

            ModifyUserResponse response = await besteUser.CreateUser(JsonConvert.SerializeObject(user, Formatting.None, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            }));

            ValiateResponse(response, ModifyUserResult.SUCCESS);

            User loginUser = new User
            {
                Username = user.Username,
                Password = user.Password
            };
            BesteUserAuthentificationResponse authResponse = await besteUser.Authenticate(JsonConvert.SerializeObject(loginUser, Formatting.None, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            }));

            ValiateResponse(authResponse, BesteUserAuthentificationResult.MUST_CHANGE_PASSWORT);

            response = await besteUser.ChangePasswordByUser(JsonConvert.SerializeObject(loginUser, Formatting.None, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            }));

            ValiateResponse(response, ModifyUserResult.SUCCESS);

            authResponse = await besteUser.Authenticate(JsonConvert.SerializeObject(loginUser, Formatting.None, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            }));

            ValiateResponse(authResponse, BesteUserAuthentificationResult.SUCCESS);
        }
コード例 #6
0
        public async Task CreateUserAndEdit()
        {
            BesteUser besteUser = new BesteUser();
            User      user      = new User
            {
                Username  = "******",
                Lastname  = "Lastname",
                Firstname = "Firstname",
                Email     = "Email",
                Password  = "******"
            };
            ModifyUserResponse response = await besteUser.CreateUser(JsonConvert.SerializeObject(user, Formatting.None, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            }));

            ValiateResponse(response, ModifyUserResult.SUCCESS);

            User loginUser = new User
            {
                Username           = "******",
                Lastname           = "Lastname",
                Firstname          = "Firstname",
                Email              = "Email",
                Password           = "******",
                MustChangePassword = false
            };

            response = await besteUser.EditUser(JsonConvert.SerializeObject(loginUser, Formatting.None, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            }));

            ValiateResponse(response, ModifyUserResult.SUCCESS);

            BesteUserAuthentificationResponse authResponse = await besteUser.Authenticate(JsonConvert.SerializeObject(loginUser, Formatting.None, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            }));

            ValiateResponse(authResponse, BesteUserAuthentificationResult.SUCCESS);
        }
コード例 #7
0
        internal async static Task HandleLogin(WebSocketHandler webSocketHandler)
        {
            User user = JsonConvert.DeserializeObject <User>(webSocketHandler.ReceivedCommand.CommandData.ToString());
            BesteUserAuthentificationResponse response = await BesteUser.Authenticate(webSocketHandler.ReceivedCommand.CommandData.ToString());

            if (response.Result == BesteUserAuthentificationResult.SUCCESS ||
                response.Result == BesteUserAuthentificationResult.MUST_CHANGE_PASSWORT)
            {
                webSocketHandler.User = response.UserData;
                List <PureRight> pureRights = new List <PureRight>();
                pureRights.Add(new PureRight
                {
                    Authorized     = true,
                    Operation      = "ChangePassword_" + webSocketHandler.User.Username,
                    RecourceModule = "User"
                });
                pureRights.Add(new PureRight
                {
                    Authorized     = true,
                    Operation      = "EditUser_" + webSocketHandler.User.Username,
                    RecourceModule = "User"
                });
                pureRights.Add(new PureRight
                {
                    Authorized     = true,
                    Operation      = "DeleteUser_" + webSocketHandler.User.Username,
                    RecourceModule = "User"
                });
                pureRights.Add(new PureRight
                {
                    Authorized     = true,
                    Operation      = "GetUser_" + webSocketHandler.User.Username,
                    RecourceModule = "User"
                });
                webSocketHandler.ConnectedUserToken = await RightControl.Register(webSocketHandler.User.Uuid, pureRights);
            }
            Command resonseCommand = new Command("AuthentificationResponse", response);
            await webSocketHandler.Send(resonseCommand);
        }
コード例 #8
0
        public async Task ForcedJsonSerializationErrors()
        {
            BesteUser          besteUser = new BesteUser();
            ModifyUserResponse response  = await besteUser.CreateUser("no json]");

            ValiateResponse(response, ModifyUserResult.JSON_ERROR);

            response = await besteUser.ChangePasswordByUser("no json]");

            ValiateResponse(response, ModifyUserResult.JSON_ERROR);

            response = await besteUser.DeleteUser("no json]");

            ValiateResponse(response, ModifyUserResult.JSON_ERROR);

            response = await besteUser.EditUser("no json]");

            ValiateResponse(response, ModifyUserResult.JSON_ERROR);

            BesteUserAuthentificationResponse authResponse = await besteUser.Authenticate("no json]");

            ValiateResponse(authResponse, BesteUserAuthentificationResult.JSON_ERROR);
        }
コード例 #9
0
        public async Task ChangeOtherUsersPasswordNotAllowed()
        {
            ClientWebSocket  webSocket        = new ClientWebSocket();
            WebSocketHandler webSocketHandler = new WebSocketHandler(webSocket);
            await webSocket.ConnectAsync(new Uri("ws://localhost:80/ws"), CancellationToken.None);

            await TestHelper.Login("UserTryChangePassword", "Passwort1$", webSocket, webSocketHandler);

            BesteUserAuthentificationResponse loginResponse = JsonConvert.DeserializeObject <BesteUserAuthentificationResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());

            User user = new User
            {
                Username           = "******",
                Password           = "******",
                MustChangePassword = false
            };
            Command command = new Command("ChangePassword", user);
            await TestHelper.ExecuteCommandAndAwaitResponse(webSocket, webSocketHandler, command);

            ModifyUserResponse response = JsonConvert.DeserializeObject <ModifyUserResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());

            TestHelper.ValiateResponse(response, ModifyUserResult.RIGHT_VIOLATION);
        }
コード例 #10
0
        internal static async Task Login(string userName, string password, ClientWebSocket webSocket, WebSocketHandler webSocketHandler)
        {
            try
            {
                byte[] buffer = new byte[1024 * 4];
                User   user   = new User
                {
                    Username = userName,
                    Password = password
                };
                Command command    = new Command("Login", user);
                string  sendString = command.ToJson();
                byte[]  sendBytes  = System.Text.UTF8Encoding.UTF8.GetBytes(sendString);
                await webSocketHandler.ExtractCompleteMessage(buffer, 60);

                if (webSocketHandler.ReceivedCommand.CommandName != "Connected")
                {
                    Assert.Fail();
                }
                await webSocket.SendAsync(new ArraySegment <byte>(sendBytes, 0, sendBytes.Length), WebSocketMessageType.Text, true, CancellationToken.None);

                await webSocketHandler.ExtractCompleteMessage(buffer, 60);

                BesteUserAuthentificationResponse authResponse = JsonConvert.DeserializeObject <BesteUserAuthentificationResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());
                if (authResponse.Result != BesteUserAuthentificationResult.SUCCESS &&
                    authResponse.Result != BesteUserAuthentificationResult.MUST_CHANGE_PASSWORT)
                {
                    Assert.Fail();
                }
                webSocketHandler.User = authResponse.UserData;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Assert.Fail();
            }
        }