public void VerifyCurrentUser_HasModelAttribute_ModelHasMoreVerifyID() { // Arrange var claims = new List <Claim>() { new Claim("userid", "123") }; var context = CreateHttpContext(CreatePrincipal(claims)); var actionValue = new Dictionary <string, object>() { { "id", new UserDtoWithMoreAttribute() { Id = "123", Name = "123" } } }; var actionExecContext = CreateActionExecutingContext(actionValue, controllerMehtodName, typeof(CommonController_ModelType_HasAttribute_MoreVerifyIdMarked), context); // Act var filter = new VerifyCurrentUserFilter(Options.Create(new MiCakeIdentityOptions())); // Assert Assert.ThrowsAsync <ArgumentException>(async() => { await filter.OnActionExecutionAsync(actionExecContext, FilterDelegate); }); }
public async void VerifyCurrentUser_HasModelAttribute_ModelNoVerifyID_WithSameClaim() { // Arrange var claims = new List <Claim>() { new Claim("userid", "123") }; var context = CreateHttpContext(CreatePrincipal(claims)); var actionValue = new Dictionary <string, object>() { { "id", new UserDtoWithAttribute() { Id = "123" } } }; var actionExecContext = CreateActionExecutingContext(actionValue, controllerMehtodName, typeof(CommonController_ModelType_HasAttribute_NoVerifyIdMarked), context); // Act var filter = new VerifyCurrentUserFilter(Options.Create(new MiCakeIdentityOptions())); await filter.OnActionExecutionAsync(actionExecContext, FilterDelegate); // Assert var response = context.Response; Assert.Equal(302, response.StatusCode); //because this model has no verifyUserIDAttribute. }
public async void VerifyCurrentUser_HasModelAttribute_WithWrongClaim() { // Arrange var claims = new List <Claim>() { new Claim(VerifyUserClaims.UserID, "524") }; var context = CreateHttpContext(CreatePrincipal(claims)); var actionValue = new Dictionary <string, object>() { { "id", new UserDtoWithAttribute() { Id = "123" } } }; var actionExecContext = CreateActionExecutingContext(actionValue, controllerMehtodName, typeof(CommonController_ModelType_HasAttribute), context); // Act var filter = new VerifyCurrentUserFilter(); await filter.OnActionExecutionAsync(actionExecContext, FilterDelegate); // Assert var response = context.Response; Assert.Equal(302, response.StatusCode); }
public async void VerifyCurrentUser_DefaultController_HasNoAnyAttribute() { // Arrange var context = CreateHttpContext(null); var actionExecContext = CreateActionExecutingContext(new Dictionary <string, object>(), controllerMehtodName, typeof(CommonController), context); // Act var filter = new VerifyCurrentUserFilter(Options.Create(new MiCakeIdentityOptions())); await filter.OnActionExecutionAsync(actionExecContext, FilterDelegate); // Assert var response = context.Response; Assert.Equal(200, response.StatusCode); }
public async void VerifyCurrentUser_HasAttributeAction_ButNoUserClaim() { // Arrange var context = CreateHttpContext(null); var actionValue = new Dictionary <string, object>() { { "id", 123 } }; var actionExecContext = CreateActionExecutingContext(actionValue, controllerMehtodName, typeof(CommonController_PrimitivesType_HasAttribute), context); // Act var filter = new VerifyCurrentUserFilter(Options.Create(new MiCakeIdentityOptions())); await filter.OnActionExecutionAsync(actionExecContext, FilterDelegate); // Assert var response = context.Response; Assert.Equal(302, response.StatusCode); }
public async void VerifyCurrentUser_HasAttributeAction_HasWrongClaim() { // Arrange var claims = new List <Claim>() { new Claim("userid", "339") }; var context = CreateHttpContext(CreatePrincipal(claims)); var actionValue = new Dictionary <string, object>() { { "id", 123 } }; var actionExecContext = CreateActionExecutingContext(actionValue, controllerMehtodName, typeof(CommonController_PrimitivesType_HasAttribute), context); // Act var filter = new VerifyCurrentUserFilter(Options.Create(new MiCakeIdentityOptions())); await filter.OnActionExecutionAsync(actionExecContext, FilterDelegate); // Assert var response = context.Response; Assert.Equal(302, response.StatusCode); //because value is different. }
public async void VerifyCurrentUser_ComplexType() { // Arrange var claims = new List <Claim>() { new Claim("userid", "123") }; var context = CreateHttpContext(CreatePrincipal(claims)); var actionValue = new Dictionary <string, object>() { { "id", new Version(1, 2, 3) } }; var actionExecContext = CreateActionExecutingContext(actionValue, controllerMehtodName, typeof(CommonController_VersionType__HasAttribute), context); // Act var filter = new VerifyCurrentUserFilter(Options.Create(new MiCakeIdentityOptions())); await filter.OnActionExecutionAsync(actionExecContext, FilterDelegate); // Assert var response = context.Response; Assert.Equal(302, response.StatusCode); //beacuse version to string is not same with 123. }
public async void VerifyCurrentUser_HasNoAttributeAction_HasDifferentClaim() { // Arrange var claims = new List <Claim>() { new Claim(VerifyUserClaims.UserID, "123") }; var context = CreateHttpContext(CreatePrincipal(claims)); var actionValue = new Dictionary <string, object>() { { "id", 339 } }; var actionExecContext = CreateActionExecutingContext(actionValue, controllerMehtodName, typeof(CommonController_PrimitivesType_HasNoAttribute), context); // Act var filter = new VerifyCurrentUserFilter(); await filter.OnActionExecutionAsync(actionExecContext, FilterDelegate); // Assert var response = context.Response; Assert.Equal(200, response.StatusCode); //because has no attribute. }
public void VerifyCurrentUser_HasMoreAttribute() { // Arrange var claims = new List <Claim>() { new Claim(VerifyUserClaims.UserID, "123") }; var context = CreateHttpContext(CreatePrincipal(claims)); var actionValue = new Dictionary <string, object>() { { "id", 123 } }; var actionExecContext = CreateActionExecutingContext(actionValue, controllerMehtodName, typeof(CommonController_PrimitivesType_HasMoreAttribute), context); // Act var filter = new VerifyCurrentUserFilter(); // Assert Assert.ThrowsAsync <ArgumentException>(async() => { await filter.OnActionExecutionAsync(actionExecContext, FilterDelegate); }); //beacuse has more CurrentUserAttribute. }
public async void VerifyCurrentUser_WithGuidType() { // Arrange var useIDValue = Guid.NewGuid(); var claims = new List <Claim>() { new Claim("userid", useIDValue.ToString()) }; var context = CreateHttpContext(CreatePrincipal(claims)); var actionValue = new Dictionary <string, object>() { { "id", useIDValue } }; var actionExecContext = CreateActionExecutingContext(actionValue, controllerMehtodName, typeof(CommonController_GuidType__HasAttribute), context); // Act var filter = new VerifyCurrentUserFilter(Options.Create(new MiCakeIdentityOptions())); await filter.OnActionExecutionAsync(actionExecContext, FilterDelegate); // Assert var response = context.Response; Assert.Equal(200, response.StatusCode); }