示例#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"));
 }
        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));
        }