public void ApiKeyAuthorizeAttributeReturns400WhenApiKeyFormatIsInvalid() { ApiKeyAuthorizeAttribute attribute = CreateAttribute(); // Act var result = attribute.CheckForResult("invalid-key"); // Assert ResultAssert.IsStatusCode(result, 400, String.Format(Strings.InvalidApiKey, "invalid-key")); }
public void ApiKeyAuthorizeAttributeReturns400WhenApiKeyIsMissing(string value) { ApiKeyAuthorizeAttribute attribute = CreateAttribute(); // Act var result = attribute.CheckForResult(value); // Assert ResultAssert.IsStatusCode(result, 400, String.Format(Strings.InvalidApiKey, "")); }
public void ApiKeyAuthorizeAttributeReturns403WhenApiKeyDoesNotBelongToAUser() { ApiKeyAuthorizeAttribute attribute = CreateAttribute(); string unknownApiKey = Guid.NewGuid().ToString(); // Act var result = attribute.CheckForResult(unknownApiKey); // Assert ResultAssert.IsStatusCode(result, 403, String.Format(Strings.ApiKeyNotAuthorized, "push")); }
public void ApiKeyAuthorizeAttributeReturns403WhenUserIsNotYetConfirmed() { ApiKeyAuthorizeAttribute attribute = CreateAttribute(); var user = new User { UnconfirmedEmailAddress = "*****@*****.**", ApiKey = Guid.NewGuid() }; GetMock <IUserService>() .Setup(us => us.FindByApiKey(user.ApiKey)) .Returns(user); // Act var result = attribute.CheckForResult(user.ApiKey.ToString()); // Assert ResultAssert.IsStatusCode(result, 403, Strings.ApiKeyUserAccountIsUnconfirmed); }