예제 #1
0
            public void ReturnsNullIfCookieIsUnsupportedVersion()
            {
                // Arrange
                var context = new Mock<HttpContextBase>();
                var tokens = new Mock<TokenService>();
                var utils = new Utils.UtilWorker(tokens.Object);
                context.Setup(c => c.Request.Cookies)
                       .Returns(() => new HttpCookieCollection() {
                           new HttpCookie(ReviewRApiController.CookieName, "COOK%20IE!?")
                       });
                tokens.Setup(t => t.UnprotectToken("COOK IE!?", ReviewRApiController.Purpose))
                      .Throws<NotSupportedException>();

                // Act
                Assert.Null(utils.DecodeCookieToJson(context.Object));
            }
예제 #2
0
            public void ReturnsJsonOfTokenIfCookieValid()
            {
                // Arrange
                var context = new Mock<HttpContextBase>();
                var tokens = new Mock<TokenService>();
                var utils = new Utils.UtilWorker(tokens.Object);
                context.Setup(c => c.Request.Cookies)
                       .Returns(() => new HttpCookieCollection() {
                           new HttpCookie(ReviewRApiController.CookieName, "COOK%20IE!?")
                       });
                tokens.Setup(t => t.UnprotectToken("COOK IE!?", ReviewRApiController.Purpose))
                      .Returns(
                        new SessionToken(
                            new ReviewRPrincipal(
                                new ReviewRIdentity() {
                                    Email = "*****@*****.**",
                                    DisplayName = "Swedish Chef"
                                }), DateTime.UtcNow));

                // Act
                Assert.Equal(
                    "{\"userId\":0,\"displayName\":\"Swedish Chef\",\"email\":\"[email protected]\",\"emailHash\":\"67614c787f39a22a54b7dcd169a01477\",\"roles\":null}",
                    utils.DecodeCookieToJson(context.Object));
            }