mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(iam): separate a constraint failure from an invalid value in PutAccountProperties (#5240)
The key pattern and length checks answered InvalidInput while carrying the "failed to satisfy constraint" wording that every other constraint check in IamService pairs with ValidationError. The model declares InvalidInputException on the operation and says nothing about which code a pattern miss produces, so the two had drifted apart with nothing to settle them. The API Reference settles it in Common Error Types rather than the operation's own error table. ValidationError is a common error for every action, defined as "The input doesn't meet the required format or constraints", 400. InvalidInput, the one the operation declares, is "an invalid or out-of-range value was supplied for an input parameter". PutAccountProperties publishes a Key Pattern of ^[A-Za-z][A-Za-z0-9/_-]*$, a key length of 1 to 50 and a value length of 1 to 1024, and the model declares all three on accountPropertyKeyType and accountPropertyValueType. Violating a published pattern or length is a format failure; a value that satisfies them and is still wrong is not. So it is a split rather than a rename. The key pattern and length, and the value length, are now ValidationError and keep the constraint wording, which was already right for them. The Namespace/PropertyName rule stays InvalidInput: the published pattern admits a key with no slash, with several, and with a trailing one, so that rule only applies once the format is already good. Its message drops the constraint wording and reads as prose, since that wording is what made the pair look inconsistent. The same-namespace rule is unchanged. aMalformedKeyIsRejected asserted one code for seven keys that fall on both sides of that line, so it splits in two, each asserting its own code and the absence of the other. As written it could not tell a pattern failure from the slash rule. Not touched, though the same reading would question it: createServiceLinkedRole answers InvalidInput for a check that is exactly the declared constraint on AWSServiceName. Its message is prose rather than the front-end format, there is no recording either way, and CreateServiceLinkedRole's error table is structured identically to this one, so it proves nothing. Left alone rather than changed on inference. Refs #5177
This commit is contained in:
1 parent
3a8f974554
commit
5fc8b0418c
3 files changed
+62
-13
No files matched your search
@@ -2341,11 +2341,20 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
|
||||
properties.size(), namespace);
|
||||
}
|
||||
|
||||
/** The namespace half of the key, having checked the whole key against the model. */
|
||||
/**
|
||||
* The namespace half of the key, having checked the whole key against the model.
|
||||
*
|
||||
* <p>The two rejections here are not the same kind of error. The length and the pattern are
|
||||
* published constraints on the parameter, and the API Reference defines {@code ValidationError}
|
||||
* as the common error for input that "doesn't meet the required format or constraints". The
|
||||
* {@code Namespace/PropertyName} rule is not expressible in the published pattern, which admits
|
||||
* no slash, several, and a trailing one, so it is a rule the service applies after the format
|
||||
* is already satisfied: that is {@code InvalidInput}, "an invalid or out-of-range value".
|
||||
*/
|
||||
private String validateAccountPropertyKey(String key) {
|
||||
if (key == null || key.isEmpty() || key.length() > MAX_ACCOUNT_PROPERTY_KEY_LENGTH
|
||||
|| !ACCOUNT_PROPERTY_KEY_PATTERN.matcher(key).matches()) {
|
||||
throw new AwsException("InvalidInput",
|
||||
throw new AwsException("ValidationError",
|
||||
"Value '" + key + "' at 'properties' failed to satisfy constraint: Map keys "
|
||||
+ "must satisfy constraint: [Member must have length less than or "
|
||||
+ "equal to " + MAX_ACCOUNT_PROPERTY_KEY_LENGTH + ", Member must "
|
||||
@@ -2355,9 +2364,9 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
|
||||
int separator = key.indexOf('/');
|
||||
if (separator <= 0 || separator != key.lastIndexOf('/') || separator == key.length() - 1) {
|
||||
throw new AwsException("InvalidInput",
|
||||
"Value '" + key + "' at 'properties' failed to satisfy constraint: a key is "
|
||||
+ "Namespace/PropertyName, with exactly one forward slash and neither "
|
||||
+ "a leading nor a trailing one.", 400);
|
||||
"The property key '" + key + "' is not Namespace/PropertyName: a key has "
|
||||
+ "exactly one forward slash, and neither a leading nor a trailing "
|
||||
+ "one.", 400);
|
||||
}
|
||||
return key.substring(0, separator);
|
||||
}
|
||||
@@ -2365,7 +2374,7 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
|
||||
private void validateAccountPropertyValue(String key, String value) {
|
||||
if (value == null || value.isEmpty()
|
||||
|| value.length() > MAX_ACCOUNT_PROPERTY_VALUE_LENGTH) {
|
||||
throw new AwsException("InvalidInput",
|
||||
throw new AwsException("ValidationError",
|
||||
"Value at 'properties." + key + "' failed to satisfy constraint: Member must "
|
||||
+ "have length between 1 and " + MAX_ACCOUNT_PROPERTY_VALUE_LENGTH,
|
||||
400);
|
||||
|
||||
Reference in new issue
Block a user