Skip to content

Commit

Permalink
Use Bad_TooManyArguments when too many arguments are provided (#1197)
Browse files Browse the repository at this point in the history
fixes #1196
  • Loading branch information
kevinherron authored Dec 20, 2023
1 parent f1ce134 commit cd80e2e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,29 @@ public void implementationCanValidateArguments() throws UaException {
}
}

@Test
void wrongNumberOfArguments() throws ExecutionException, InterruptedException {
// too few arguments
{
CallMethodResult result = client.call(new CallMethodRequest(
Identifiers.ObjectsFolder,
NodeId.parse("ns=2;s=onlyAcceptsPositiveInputs()"),
new Variant[]{}
)).get();

assertEquals(StatusCodes.Bad_ArgumentsMissing, result.getStatusCode().getValue());
}

// too many arguments
{
CallMethodResult result = client.call(new CallMethodRequest(
Identifiers.ObjectsFolder,
NodeId.parse("ns=2;s=onlyAcceptsPositiveInputs()"),
new Variant[]{new Variant(1), new Variant(2)}
)).get();

assertEquals(StatusCodes.Bad_TooManyArguments, result.getStatusCode().getValue());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ public final CallMethodResult invoke(AccessContext accessContext, CallMethodRequ
Variant[] inputArgumentValues = request.getInputArguments();
if (inputArgumentValues == null) inputArgumentValues = new Variant[0];

if (inputArgumentValues.length != getInputArguments().length) {
if (inputArgumentValues.length < getInputArguments().length) {
throw new UaException(StatusCodes.Bad_ArgumentsMissing);
}
if (inputArgumentValues.length > getInputArguments().length) {
throw new UaException(StatusCodes.Bad_TooManyArguments);
}

StatusCode[] inputDataTypeCheckResults = new StatusCode[inputArgumentValues.length];

Expand Down Expand Up @@ -250,7 +253,8 @@ protected abstract Variant[] invoke(
* @param inputArgumentValues the input values provided by the client for the current method call.
* @throws InvalidArgumentException if one or more input argument values are invalid.
*/
protected void validateInputArgumentValues(Variant[] inputArgumentValues) throws InvalidArgumentException {}
protected void validateInputArgumentValues(Variant[] inputArgumentValues) throws InvalidArgumentException {
}

/**
* Extends {@link AccessContext} to provide additional context to implementations of
Expand Down

0 comments on commit cd80e2e

Please sign in to comment.