示例#1
0
        private static async Task CleanUpBesteRightsAuthorization()
        {
            var request = new QueryRequest
            {
                TableName     = BesteRightsAuthorization.TableName,
                KeyConditions = new Dictionary <string, Condition>
                {
                    { "TableId", new Condition()
                      {
                          ComparisonOperator = ComparisonOperator.EQ,
                          AttributeValueList = new List <AttributeValue>
                          {
                              new AttributeValue {
                                  N = TABLE_ID.ToString()
                              }
                          }
                      } }
                },
                //AttributesToGet = new List<string> { "user_id" }
            };
            var response = await AmazonDynamoDBFactory.Client.QueryAsync(request);

            foreach (var item in response.Items)
            {
                BesteRightsAuthorization auth = new BesteRightsAuthorization()
                {
                    TableId = TABLE_ID,
                    Uuid    = item["Uuid"].S
                };
                await AmazonDynamoDBFactory.Context.DeleteAsync(auth);
            }
        }
示例#2
0
        public async Task EditNotExistingServerSettingsInDatabase()
        {
            ClientWebSocket  webSocket        = new ClientWebSocket();
            WebSocketHandler webSocketHandler = new WebSocketHandler(webSocket);
            await webSocket.ConnectAsync(new Uri("ws://localhost:80/ws"), CancellationToken.None);

            await Task.Delay(50);

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

            ServerSetting serverSettings = TestHelper.GenerateNewServerSetting();

            serverSettings.GameName = "Edited!";
            serverSettings.Id       = 532345823;

            await AmazonDynamoDBFactory.ExecuteInTransactionContext(async (client, context) =>
            {
                BesteRightsAuthorization besteRightsAuthorization = new BesteRightsAuthorization
                {
                    TableId          = TABLE_ID,
                    Namespace        = "Beste.GameServer.SDaysTDie.ServerSettings",
                    Operation        = "EditServerSettings",
                    RecourceModule   = "ServerSetting",
                    RecourceId       = serverSettings.Id,
                    Authorized       = true,
                    LegitimationUuid = webSocketHandler.User.Uuid,
                    Uuid             = Guid.NewGuid().ToString()
                };
                await AmazonDynamoDBFactory.Context.SaveAsync(besteRightsAuthorization);
            });

            await webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, webSocketHandler.Result.CloseStatusDescription, CancellationToken.None);

            webSocket        = new ClientWebSocket();
            webSocketHandler = new WebSocketHandler(webSocket);
            await webSocket.ConnectAsync(new Uri("ws://localhost:80/ws"), CancellationToken.None);

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



            Command command = new Command("EditServerSettings", serverSettings);
            await TestHelper.ExecuteCommandAndAwaitResponse(webSocket, webSocketHandler, command);

            ModifySettingsResponse modifyResponse = JsonConvert.DeserializeObject <ModifySettingsResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());

            TestHelper.ValiateResponse(modifyResponse, ModifySettingsResult.SETTING_NOT_FOUND);
        }
示例#3
0
        private static async Task AddInitialRightsToDatabase()
        {
            var request = new QueryRequest
            {
                TableName     = BesteRightsAuthorization.TableName,
                KeyConditions = new Dictionary <string, Condition>
                {
                    { "TableId", new Condition()
                      {
                          ComparisonOperator = ComparisonOperator.EQ,
                          AttributeValueList = new List <AttributeValue>
                          {
                              new AttributeValue {
                                  N = TABLE_ID.ToString()
                              }
                          }
                      } }
                },
                //AttributesToGet = new List<string> { "user_id" }
            };
            var response = await AmazonDynamoDBFactory.Client.QueryAsync(request);

            foreach (var item in response.Items)
            {
                BesteRightsAuthorization user = new BesteRightsAuthorization()
                {
                    TableId = TABLE_ID,
                    Uuid    = item["Uuid"].S
                };
                await AmazonDynamoDBFactory.Context.DeleteAsync(user);
            }


            await AmazonDynamoDBFactory.ExecuteInTransactionContext(async (client, context) =>
            {
                List <BesteRightsAuthorization> besteRightsAuthorizations = new List <BesteRightsAuthorization>();
                besteRightsAuthorizations.Add(new BesteRightsAuthorization
                {
                    TableId          = TABLE_ID,
                    Namespace        = "CheckRegister",
                    Operation        = "Delete",
                    RecourceModule   = "Authorizations",
                    Authorized       = false,
                    LegitimationUuid = "1",
                    Uuid             = Guid.NewGuid().ToString()
                });
                besteRightsAuthorizations.Add(new BesteRightsAuthorization
                {
                    TableId          = TABLE_ID,
                    Namespace        = "CheckRegister",
                    Operation        = "Add",
                    RecourceModule   = "Authorizations",
                    Authorized       = true,
                    LegitimationUuid = "1",
                    Uuid             = Guid.NewGuid().ToString()
                });
                foreach (var item in besteRightsAuthorizations)
                {
                    await AmazonDynamoDBFactory.Context.SaveAsync(item);
                }
            });
        }
        private static async Task AddOrUpdateServerSettingRight(string operation, int serverSettingsId, string userUuid, string token)
        {
            BesteRightsAuthorization besteRightsAuthorizationDb = await AmazonDynamoDBFactory.ExecuteInTransactionContext(async (client, context) =>
            {
                var request = new QueryRequest
                {
                    TableName = BesteRightsAuthorization.TableName,
                    //ScanIndexForward = false,
                    KeyConditions = new Dictionary <string, Condition>
                    {
                        { "TableId", new Condition()
                          {
                              ComparisonOperator = ComparisonOperator.EQ,
                              AttributeValueList = new List <AttributeValue>
                              {
                                  new AttributeValue {
                                      N = TABLE_ID.ToString()
                                  }
                              }
                          } }
                    },
                    ExpressionAttributeNames = new Dictionary <string, string>
                    {
                        { "#Namespace", "Namespace" },
                        { "#Operation", "Operation" },
                        { "#RecourceModule", "RecourceModule" },
                        { "#RecourceId", "RecourceId" }
                    },
                    ExpressionAttributeValues = new Dictionary <string, AttributeValue>
                    {
                        { ":Namespace", new AttributeValue {
                              S = "Beste.GameServer.SDaysTDie.ServerSettings"
                          } },
                        { ":Operation", new AttributeValue {
                              S = operation
                          } },
                        { ":RecourceModule", new AttributeValue {
                              S = "ServerSetting"
                          } },
                        { ":RecourceId", new AttributeValue {
                              N = serverSettingsId.ToString()
                          } }
                    },
                    FilterExpression = "#Namespace = :Namespace and" +
                                       "#Operation = :Operation and" +
                                       "#RecourceModule = :RecourceModule and" +
                                       "#RecourceId = :RecourceId"
                };
                var response = await client.QueryAsync(request);
                if (response.Items.Count > 0)
                {
                    return(new BesteRightsAuthorization
                    {
                        TableId = TABLE_ID,
                        Uuid = response.Items[0]["Uuid"].S
                    });
                }
                return(null);
            });

            await AmazonDynamoDBFactory.ExecuteInTransactionContext(async (client, context) =>
            {
                BesteRightsAuthorization besteRightsAuthorization = new BesteRightsAuthorization
                {
                    TableId          = TABLE_ID,
                    Namespace        = "Beste.GameServer.SDaysTDie.ServerSettings",
                    Operation        = operation,
                    RecourceModule   = "ServerSetting",
                    RecourceId       = serverSettingsId,
                    Authorized       = true,
                    LegitimationUuid = userUuid,
                    Uuid             = besteRightsAuthorizationDb == null ?
                                       Guid.NewGuid().ToString() :
                                       besteRightsAuthorizationDb.Uuid
                };
                await context.SaveAsync(besteRightsAuthorization);
            });

            RightControl.Grant(token, operation, "ServerSetting", serverSettingsId);
        }