コード例 #1
0
        private async Task UpdateTokensAndAppendCustomHeaders(ActionExecutingContext actionContext)
        {
            var tokenFilter =
                new SetAngularAntiForgeryTokensAttribute.SetAngularAntiForgeryTokensFilter(_backOfficeAntiforgery);
            await tokenFilter.OnActionExecutionAsync(
                actionContext,
                () => Task.FromResult(new ActionExecutedContext(actionContext, new List <IFilterMetadata>(), new { })));

            // add the header
            AppendUserModifiedHeaderAttribute.AppendHeader(actionContext);
        }
コード例 #2
0
    public void Does_Not_Append_Header_When_User_Id_Parameter_Provided_And_Does_Not_Match_Current_User()
    {
        // Arrange
        var context         = CreateContext(actionArgument: new KeyValuePair <string, object>("UserId", 99));
        var userIdParameter = "UserId";
        var attribute       = new AppendUserModifiedHeaderAttribute(userIdParameter);

        // Act
        attribute.OnActionExecuting(context);

        // Assert
        Assert.IsFalse(context.HttpContext.Response.Headers.ContainsKey("X-Umb-User-Modified"));
    }
コード例 #3
0
    public void Does_Not_Append_Header_If_Already_Exists()
    {
        // Arrange
        var context   = CreateContext("0");
        var attribute = new AppendUserModifiedHeaderAttribute();

        // Act
        attribute.OnActionExecuting(context);

        // Assert
        context.HttpContext.Response.Headers.TryGetValue("X-Umb-User-Modified", out var headerValue);
        Assert.AreEqual("0", headerValue[0]);
    }
コード例 #4
0
    public void Appends_Header_When_No_User_Parameter_Provider()
    {
        // Arrange
        var context   = CreateContext();
        var attribute = new AppendUserModifiedHeaderAttribute();

        // Act
        attribute.OnActionExecuting(context);

        // Assert
        context.HttpContext.Response.Headers.TryGetValue("X-Umb-User-Modified", out var headerValue);
        Assert.AreEqual("1", headerValue[0]);
    }
コード例 #5
0
    public void Appends_Header_When_User_Id_Parameter_Provided_And_Does_Not_Match_Current_User()
    {
        // Arrange
        var context         = CreateContext(actionArgument: new KeyValuePair <string, object>("UserId", 100));
        var userIdParameter = "UserId";
        var attribute       = new AppendUserModifiedHeaderAttribute(userIdParameter);

        // Act
        attribute.OnActionExecuting(context);

        // Assert
        context.HttpContext.Response.Headers.TryGetValue("X-Umb-User-Modified", out var headerValue);
        Assert.AreEqual("1", headerValue[0]);
    }