Exemplo n.º 1
0
        public async Task CreateMatchFailDueToNoItemsPlaced()
        {
            var percentage         = 12.4587;
            var percentageAsString = percentage.ToString(CultureInfo.InvariantCulture);

            var salt = "randomSalt";
            var hash = "ranomdHash";

            var creatorUser = new DatabaseModel.User("steamId", "name", "imageURl", null, DateTime.Today, DateTime.Today, false, null, 10);
            var gameMode    = new DatabaseModel.GameMode
            {
                CurrentSettingId = 1,
                IsEnabled        = true,
                Type             = GameModeHelper.GetStringFromType(GameModeType.CoinFlip),
                Id = 2
            };

            A.CallTo(() => _fakedRandomService.GeneratePercentage()).Returns(percentageAsString);
            A.CallTo(() => _fakedRandomService.GenerateSalt()).Returns(salt);
            A.CallTo(() => _fakedHashService.CreateBase64Sha512Hash(percentageAsString, salt)).Returns(hash);
            A.CallTo(() => _fakedUserRepoService.FindAsync(creatorUser.SteamId)).Returns(creatorUser);

            A.CallTo(() => _fakedGameModeRepoSerivce.Find(GameModeHelper.GetStringFromType(GameModeType.CoinFlip))).Returns(gameMode);

            var itemList = new List <AssetAndDescriptionId>();

            await Assert.ThrowsAsync <InvalidBetException>(async() =>
                                                           await _coinFlipService.CreateMatch(creatorUser.SteamId, true, itemList, _defaultSetting));

            A.CallTo(() => _fakedCoinFlipMatchRepoService.InsertAsync(A <DatabaseModel.CoinFlip> ._, A <ITransactionWrapper> ._)).MustNotHaveHappened();
            A.CallTo(() => _fakedUserRepoService.FindAsync(creatorUser.SteamId)).MustHaveHappened();
        }
Exemplo n.º 2
0
        public async void CreateNewMatchSuccess()
        {
            var matchInsert =
                new DatabaseModel.Match(1, "salt", "hash", "10", 1, null, null, 1, 1, DateTime.Now);
            var matchReturn = new DatabaseModel.Match(1, "salt", "hash", 10.ToString(CultureInfo.InvariantCulture), 1, null, null, 1, 1,
                                                      default(DateTime), 1);

            A.CallTo(() => _fakeMatchRepoServicey.InsertAsync(
                         A <DatabaseModel.Match> .That.Matches(m =>
                                                               m.Hash == matchInsert.Hash &&
                                                               m.Salt == matchInsert.Salt &&
                                                               m.Percentage == matchInsert.Percentage &&
                                                               m.RoundId == matchInsert.RoundId &&
                                                               m.Status == matchInsert.Status
                                                               )
                         )).Returns(matchReturn);

            A.CallTo(() => _fakeHashService.CreateBase64Sha512Hash(A <string> ._, A <string> ._)).Returns("hash");
            A.CallTo(() => _fakeRandomService.GeneratePercentage()).Returns("10");
            A.CallTo(() => _fakeRandomService.GenerateSalt()).Returns("salt");

            A.CallTo(() => _fakedGameModeSettingService.GetSettingForType(GameModeType.JackpotCsgo))
            .Returns(new DatabaseModel.JackpotSetting(0, 0, 0, 0, 0, 0, 0, 0, true, false, ""));
            A.CallTo(() => _fakedGameModeSettingService.Find(A <int> ._, A <GameModeType> ._))
            .Returns(new DatabaseModel.JackpotSetting(0, 0, 0, 0, 0, 0, 0, 0, true, false, ""));

            var jackpotMatchManager = new JackpotMatchManager(
                _fakedRepoServiceFactory,
                _fakeBetService,
                _fakeHashService,
                _fakeRandomService,
                A.Dummy <IJackpotDraftService>(),
                A.Dummy <ILogServiceFactory>(),
                A.Dummy <IBetOrWithdrawQueueManager>(),
                _fakedGameModeSettingService,
                _fakedBetHub,
                _fakedMatchHub,
                A.Dummy <IDiscordService>()
                );
            var match = await jackpotMatchManager.CreateNewMatchAsync(1);


            A.CallTo(() => _fakeMatchRepoServicey.InsertAsync(
                         A <DatabaseModel.Match> .That.Matches(m =>
                                                               m.Hash == matchInsert.Hash &&
                                                               m.Salt == matchInsert.Salt &&
                                                               m.Percentage == matchInsert.Percentage &&
                                                               m.RoundId == matchInsert.RoundId &&
                                                               m.Status == matchInsert.Status
                                                               ))).MustHaveHappened();
            A.CallTo(() => _fakeHashService.CreateBase64Sha512Hash(A <string> ._, A <string> ._)).MustHaveHappened();
            A.CallTo(() => _fakeRandomService.GeneratePercentage()).MustHaveHappened();
            A.CallTo(() => _fakeRandomService.GenerateSalt()).MustHaveHappened();
            Assert.Equal(1, match.Id);
        }
Exemplo n.º 3
0
        public Token CreatePasswordResetToken(User user)
        {
            var secret = _hashService.CreateBase64Sha512Hash(user.Password, user.Created.ToString());

            var claims = new Dictionary <string, object>
            {
                { CustomClaims.ValidationType, "passwordReset" },
                { CustomClaims.Secret, secret },
                { CustomClaims.Id, user.Id },
            };

            return(CreateValidationToken(claims));
        }
        public async Task <TokenValidationResult> IsPasswordResetValid(string tokenString)
        {
            if (!TryDecodeToken(tokenString, out var token))
            {
                return new TokenValidationResult
                       {
                           Error   = TokenValidationError.InvalidOrExpiered,
                           Success = false
                       }
            }
            ;

            if (token[CustomClaims.ValidationType] != "passwordReset")
            {
                return new TokenValidationResult
                       {
                           Error   = TokenValidationError.InvalidValidationType,
                           Success = false
                       }
            }
            ;

            var userId          = int.Parse(token[CustomClaims.Id]);
            var secretFromToken = token[CustomClaims.Secret];

            var user = await _userService.FindAsync(userId);

            var secret = _hashService.CreateBase64Sha512Hash(user.Password, user.Created.ToString());

            if (secretFromToken != secret)
            {
                return new TokenValidationResult
                       {
                           Error   = TokenValidationError.InvalidSecret,
                           Success = false,
                       }
            }
            ;

            return(new TokenValidationResult
            {
                TokenOwner = user,
                Success = true,
                Token = token
            });
        }
Exemplo n.º 5
0
        public async Task <string> CreatePreHash(string steamId)
        {
            var percentage = _randomService.GeneratePercentage();
            var salt       = _randomService.GenerateSalt();
            var hash       = _hashService.CreateBase64Sha512Hash(percentage, salt);
            var preHash    = new MongoDbModels.PreHash
            {
                Created     = DateTime.Now,
                Hash        = hash,
                Percentage  = percentage,
                Salt        = salt,
                UserSteamId = steamId
            };

            await _preHashRepoService.Insert(preHash);

            return(preHash.Hash);
        }
Exemplo n.º 6
0
        protected async Task <DatabaseModel.Match> CreateNewMatchAsync(int roundId, DatabaseModel.GameMode currentGameMode)
        {
            var percentage = _randomService.GeneratePercentage();
            var salt       = _randomService.GenerateSalt();
            var hash       = _hashService.CreateBase64Sha512Hash(percentage, salt);
            var status     = MatchStatusHelper.GetIntFromMatchStatus(MatchStatus.Open);

            var match = new DatabaseModel.Match
                        (
                roundId,
                salt,
                hash,
                percentage,
                status,
                null,
                null,
                currentGameMode.CurrentSettingId,
                currentGameMode.Id,
                DateTime.Now
                        );

            return(await _matchRepoService.InsertAsync(match));
        }