예제 #1
0
 public void InvalidTokens()
 {
     Assert.IsNull(AuthenticationToken.Parse("[email protected];34x21;"));
     Assert.IsNull(AuthenticationToken.Parse("ud;3421;"));
     Assert.IsNull(AuthenticationToken.Parse("[email protected];;xxczd"));
     Assert.IsNull(AuthenticationToken.Parse("[email protected];12345678912345;xxczd"));
 }
예제 #2
0
        private void Authenticate(HttpAuthenticationContext context)
        {
            var headers = context.Request.Headers;

            if (!headers.Contains("X-Authentication-Token"))
            {
                return;
            }
            var fullTokenString = headers.GetValues("X-Authentication-Token").FirstOrDefault();
            var token           = AuthenticationToken.Parse(fullTokenString);

            if (token == null || !token.Valid)
            {
                return;
            }

            if (token.Equals(adminToken))
            {
                var judge = new Judge
                {
                    IsAdmin = true,
                    JudgeId = "admin",
                    Name    = "Admin"
                };
                context.Principal = new JudgePrincipal(judge);
            }
            else
            {
                var repository = repositorySetProvider.GetRepositorySet(token.RaceId).Judges;

                var judge = repository.FindJudge(token.JudgeId);
                if (judge == null)
                {
                    return;
                }

                var tokenVerified = repository.FindJudgesDevices(token.JudgeId).Any(d => d.AuthenticationToken == fullTokenString);
                if (!tokenVerified)
                {
                    return;
                }

                context.Principal = new JudgePrincipal(judge);
            }
        }
예제 #3
0
 public void UnparsableTokenReturnsNull()
 {
     Assert.That(AuthenticationToken.Parse(""), Is.Null);
 }
예제 #4
0
        public void ParsedTokenIsEqualToOriginal()
        {
            var token1 = AuthenticationToken.Build("race01", "judge01", "lkjdlcvjlker");

            Assert.That(AuthenticationToken.Parse(token1.ToString()), Is.EqualTo(token1));
        }
예제 #5
0
        public void ParseValidTokenWithNoExtraDataWithTrailingSeparator()
        {
            AuthenticatedUserInfo info = AuthenticationToken.Parse("[email protected];3421;");

            CheckUserInfoValues(info, 3421, "*****@*****.**", string.Empty);
        }
예제 #6
0
        public void ParseValidTokenWithExtraData()
        {
            AuthenticatedUserInfo info = AuthenticationToken.Parse("[email protected];3421;some short data here");

            CheckUserInfoValues(info, 3421, "*****@*****.**", "some short data here");
        }
예제 #7
0
        public static AuthenticationToken GetAdminToken()
        {
            var adminTokenString = ConfigurationManager.AppSettings["authentication:admin"];

            return(AuthenticationToken.Parse(adminTokenString));
        }