[InlineData(";NAME;VAL:UE")] // missing domain public void ThrowsForInvalidFormat(string flagValue) { var factory = new CookieActionFactory(); var ex = Assert.Throws <FormatException>(() => CookieActionFactory.Create(flagValue)); Assert.Equal(Resources.FormatError_InvalidChangeCookieFlag(flagValue), ex.Message); }
public void ThrowsForInvalidIntFormat(string badInt) { var factory = new CookieActionFactory(); var ex = Assert.Throws <FormatException>(() => CookieActionFactory.Create("NAME:VALUE:DOMAIN:" + badInt)); Assert.Equal(Resources.FormatError_CouldNotParseInteger(badInt), ex.Message); }
[InlineData(" NAME : v : ", "v", null)] // trims values public void TrimsValues(string flagValue, string value, string domain) { var factory = new CookieActionFactory(); var action = CookieActionFactory.Create(flagValue); Assert.Equal("NAME", action.Name); Assert.NotNull(action.Value); Assert.Equal(value, action.Value); Assert.Equal(domain, action.Domain); }
public void Creates_HttpOnly() { var action = CookieActionFactory.Create(";NAME;VALUE;DOMAIN;;;;httponly"); Assert.Equal("NAME", action.Name); Assert.Equal("VALUE", action.Value); Assert.Equal("DOMAIN", action.Domain); Assert.Equal(0, action.Lifetime.TotalSeconds); Assert.Equal(string.Empty, action.Path); Assert.False(action.Secure); Assert.True(action.HttpOnly); }
public void Creates_OneCookie_AltSeparator() { var action = CookieActionFactory.Create(";NAME;VALUE:WithColon;DOMAIN;1440;path;secure;httponly"); Assert.Equal("NAME", action.Name); Assert.Equal("VALUE:WithColon", action.Value); Assert.Equal("DOMAIN", action.Domain); Assert.Equal(TimeSpan.FromMinutes(1440), action.Lifetime); Assert.Equal("path", action.Path); Assert.True(action.Secure); Assert.True(action.HttpOnly); }
public void Creates_OneCookie() { var cookie = CookieActionFactory.Create("NAME:VALUE:DOMAIN:1440:path:secure:httponly"); Assert.Equal("NAME", cookie.Name); Assert.Equal("VALUE", cookie.Value); Assert.Equal("DOMAIN", cookie.Domain); Assert.Equal(TimeSpan.FromMinutes(1440), cookie.Lifetime); Assert.Equal("path", cookie.Path); Assert.True(cookie.Secure); Assert.True(cookie.HttpOnly); }
public void AddAction( Pattern pattern, Flags flags) { if (flags.GetValue(FlagType.Cookie, out var flag)) { var action = CookieActionFactory.Create(flag); _actions.Add(action); } if (flags.GetValue(FlagType.Env, out _)) { throw new NotSupportedException(Resources.Error_ChangeEnvironmentNotSupported); } if (flags.HasFlag(FlagType.Forbidden)) { _actions.Add(new ForbiddenAction()); } else if (flags.HasFlag(FlagType.Gone)) { _actions.Add(new GoneAction()); } else { var escapeBackReference = flags.HasFlag(FlagType.EscapeBackreference); var queryStringAppend = flags.HasFlag(FlagType.QSAppend); var queryStringDelete = flags.HasFlag(FlagType.QSDiscard); // is redirect? if (flags.GetValue(FlagType.Redirect, out var statusCode)) { int responseStatusCode; if (string.IsNullOrEmpty(statusCode)) { responseStatusCode = StatusCodes.Status302Found; } else if (!int.TryParse(statusCode, NumberStyles.None, CultureInfo.InvariantCulture, out responseStatusCode)) { throw new FormatException(Resources.FormatError_InputParserInvalidInteger(statusCode, -1)); } _actions.Add(new RedirectAction(responseStatusCode, pattern, queryStringAppend, queryStringDelete, escapeBackReference)); } else { var last = flags.HasFlag(FlagType.End) || flags.HasFlag(FlagType.Last); var termination = last ? RuleResult.SkipRemainingRules : RuleResult.ContinueRules; _actions.Add(new RewriteAction(termination, pattern, queryStringAppend, queryStringDelete, escapeBackReference)); } } }