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); } }
public void UnparsableTokenReturnsNull() { Assert.That(AuthenticationToken.Parse(""), Is.Null); }
public void ParsedTokenIsEqualToOriginal() { var token1 = AuthenticationToken.Build("race01", "judge01", "lkjdlcvjlker"); Assert.That(AuthenticationToken.Parse(token1.ToString()), Is.EqualTo(token1)); }
public void ParseValidTokenWithNoExtraDataWithTrailingSeparator() { AuthenticatedUserInfo info = AuthenticationToken.Parse("[email protected];3421;"); CheckUserInfoValues(info, 3421, "*****@*****.**", string.Empty); }
public void ParseValidTokenWithExtraData() { AuthenticatedUserInfo info = AuthenticationToken.Parse("[email protected];3421;some short data here"); CheckUserInfoValues(info, 3421, "*****@*****.**", "some short data here"); }
public static AuthenticationToken GetAdminToken() { var adminTokenString = ConfigurationManager.AppSettings["authentication:admin"]; return(AuthenticationToken.Parse(adminTokenString)); }