Inheritance: IAntiforgeryTokenGenerator
コード例 #1
0
ファイル: AntiforgeryHelper.cs プロジェクト: frapid/frapid
        public static MvcHtmlString GetAntiForgeryToken(this HtmlHelper helper, Uri url)
        {
            var logger = Log.Logger;
            var serializer = new ApprovedDomainSerializer();
            var check = new StaticDomainCheck(logger, serializer);
            var tokenizer = new AntiforgeryTokenizer(helper);
            string currentDomain = GetDomainName(url);

            var generator = new AntiforgeryTokenGenerator(check, tokenizer, currentDomain);
            return generator.GetAntiForgeryToken();
        }
コード例 #2
0
        public void Test(string currentDomain, string expectedToken)
        {
            var logger = new FakeLogger();
            var serializer = new FakeDomainSerializer();
            var check = new StaticDomainCheck(logger, serializer);
            var tokenizer = new FakeTokenizer();

            var generator = new AntiforgeryTokenGenerator(check, tokenizer, currentDomain);
            var result = generator.GetAntiForgeryToken();
            var expected = new MvcHtmlString(expectedToken);

            Assert.Equal(expected.ToString(), result.ToString());
        }