Skip to content

Commit

Permalink
Merge pull request #68 from prime-framework/degroff/fuzzing_noise
Browse files Browse the repository at this point in the history
Reduce noise from fuzzing, or various unexpected inputs
  • Loading branch information
robotdan authored Jan 23, 2025
2 parents 967640f + def78f4 commit 95ee8cf
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public String getMessage(String key, Object... values) throws MissingMessageExce
String message = getOptionalMessage(key, values);
if (message == null) {
ActionInvocation actionInvocation = invocationStore.getCurrent();
throw new MissingMessageException("Message could not be found for the URI [" + actionInvocation.actionURI + "] and key [" + key + "]");
String uri = actionInvocation != null ? actionInvocation.actionURI : null;
throw new MissingMessageException("Message could not be found for the URI [" + uri + "] and key [" + key + "]");
}

return message;
Expand All @@ -96,7 +97,8 @@ public String getOptionalMessage(String key, Object... values) {

if (template == null) {
if (!"[ValidationException]".equals(key)) {
logger.debug("Message could not be found for the URI [{}] and key [{}]", actionInvocation.actionURI, key);
String uri = actionInvocation != null ? actionInvocation.actionURI : null;
logger.debug("Message could not be found for the URI [{}] and key [{}]", uri, key);
}

return null;
Expand Down Expand Up @@ -131,12 +133,13 @@ protected Queue<String> determineBundles(String bundle) {
* @return The message or null if it doesn't exist.
*/
protected String findMessage(ActionInvocation actionInvocation, String key) {
String message = findMessage(actionInvocation.actionURI, key);
String actionURI = actionInvocation != null ? actionInvocation.actionURI : "/";
String message = findMessage(actionURI, key);
if (message != null) {
return message;
}

ActionConfiguration config = actionInvocation.configuration;
ActionConfiguration config = actionInvocation != null ? actionInvocation.configuration : null;
if (config == null) {
return null;
}
Expand Down
7 changes: 5 additions & 2 deletions src/test/java/messages/package.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2001-2007, Inversoft Inc., All Rights Reserved
# Copyright (c) 2001-2025, Inversoft Inc., All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -14,4 +14,7 @@
# language governing permissions and limitations under the License.
#
key=Super Package Message
format_key=Super Package Message %s %s %s
format_key=Super Package Message %s %s %s

# Default messages
[blank]=Required
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001-2024, Inversoft Inc., All Rights Reserved
* Copyright (c) 2001-2025, Inversoft Inc., All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -142,6 +142,31 @@ public void missing() {
verify(store);
}

@Test
public void noActionInvocation() {
HTTPContext context = new HTTPContext(Path.of("src/test/java"));
ActionInvocationStore store = createStrictMock(ActionInvocationStore.class);
expect(store.getCurrent()).andReturn(null).times(3);
replay(store);

LocaleProvider localeProvider = createStrictMock(LocaleProvider.class);
expect(localeProvider.get()).andReturn(Locale.US).anyTimes();
replay(localeProvider);

ResourceBundleMessageProvider provider = new ResourceBundleMessageProvider(localeProvider, new WebControl(new ServletContainerResolver(context), configuration), store);
assertEquals(provider.getMessage("[blank]foo.bar"), "Required");

// Really missing
try {
provider.getMessage("[not_found]bar");
fail("Should have failed");
} catch (MissingMessageException e) {
// Expected
}

verify(store);
}

@Test
public void search() {
HTTPContext context = new HTTPContext(Path.of("src/test/java"));
Expand Down
5 changes: 4 additions & 1 deletion src/test/web/messages/package.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2001-2022, Inversoft Inc., All Rights Reserved
# Copyright (c) 2001-2025, Inversoft Inc., All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -23,3 +23,6 @@ format_key=Super Package Message %s %s %s
[UnsupportedContentType]=Unsupported [Content-Type] HTTP request header value of [%s].

[invalidJSON]=Unable to parse JSON. The property [%s] was invalid. The error was [%s]. The detailed exception was [%s].

# Default messages
[blank]=Required

0 comments on commit 95ee8cf

Please sign in to comment.