Skip to content

Commit 6b45eea

Browse files
author
Vladimir Kotal
committed
better error messages
1 parent 9464be8 commit 6b45eea

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

plugins/src/opengrok/auth/plugin/decoders/MellonHeaderDecoder.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import opengrok.auth.plugin.entity.User;
2727

2828
import javax.servlet.http.HttpServletRequest;
29+
import java.util.Collections;
2930
import java.util.logging.Level;
3031
import java.util.logging.Logger;
3132

@@ -53,7 +54,9 @@ public User fromRequest(HttpServletRequest request) {
5354
String username = request.getHeader(MELLON_EMAIL_HEADER);
5455
if (username == null || username.isEmpty()) {
5556
LOGGER.log(Level.WARNING,
56-
"Can not construct an user: username could not be extracted");
57+
"Can not construct User object: header ''{1}'' not found in request headers: {0}",
58+
new Object[]{String.join(",", Collections.list(request.getHeaderNames())),
59+
MELLON_EMAIL_HEADER});
5760
return null;
5861
}
5962

plugins/src/opengrok/auth/plugin/decoders/OSSOHeaderDecoder.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323
package opengrok.auth.plugin.decoders;
2424

25+
import java.util.Collections;
2526
import java.util.Date;
2627
import java.util.logging.Level;
2728
import java.util.logging.Logger;
@@ -57,13 +58,15 @@ public User fromRequest(HttpServletRequest request) {
5758

5859
if (username == null || username.isEmpty()) {
5960
LOGGER.log(Level.WARNING,
60-
"Can not construct an user: username could not be extracted");
61+
"Can not construct an user: username could not be extracted from headers: {0}",
62+
String.join(",", Collections.list(request.getHeaderNames())));
6163
return null;
6264
}
6365

6466
if (userguid == null || userguid.isEmpty()) {
6567
LOGGER.log(Level.WARNING,
66-
"Can not construct an user: userguid could not be extracted");
68+
"Can not construct an user: userguid could not be extracted from headers: {0}",
69+
String.join(",", Collections.list(request.getHeaderNames())));
6770
return null;
6871
}
6972

@@ -74,8 +77,8 @@ public User fromRequest(HttpServletRequest request) {
7477
cookieTimestamp = Timestamp.decodeTimeCookie(timestamp);
7578
} catch (NumberFormatException ex) {
7679
LOGGER.log(Level.WARNING,
77-
String.format("Unparseable timestamp cookie \"%s\" for user \"%s\"", timestamp, username),
78-
ex);
80+
String.format("Unparseable timestamp cookie \"%s\" for user \"%s\"",
81+
timestamp, username), ex);
7982
}
8083

8184
/**
@@ -89,7 +92,8 @@ public User fromRequest(HttpServletRequest request) {
8992
user.setAttribute("subscriber", request.getHeader(OSSO_SUBSCRIBER_HEADER));
9093

9194
if (user.isTimeouted()) {
92-
LOGGER.log(Level.WARNING, "Can not construct an user \"{0}\": header is timeouted", username);
95+
LOGGER.log(Level.WARNING, "Can not construct an user \"{0}\": header is timeouted",
96+
username);
9397
return null;
9498
}
9599

plugins/test/opengrok/auth/plugin/decoders/MellonDecoderTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.junit.Test;
3131

3232
import static opengrok.auth.plugin.decoders.MellonHeaderDecoder.MELLON_EMAIL_HEADER;
33+
import static org.junit.Assert.assertNull;
3334

3435
public class MellonDecoderTest {
3536
DummyHttpServletRequestUser dummyRequest;
@@ -47,7 +48,12 @@ public void testAll() {
4748

4849
Assert.assertNotNull(result);
4950
Assert.assertEquals("[email protected]", result.getUsername());
50-
Assert.assertNull(result.getId());
51+
assertNull(result.getId());
5152
Assert.assertFalse(result.isTimeouted());
5253
}
54+
55+
@Test
56+
public void testMissingHeader() {
57+
assertNull(decoder.fromRequest(new DummyHttpServletRequestUser()));
58+
}
5359
}

plugins/test/opengrok/auth/plugin/util/DummyHttpServletRequestUser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public Enumeration<String> getHeaders(String string) {
172172

173173
@Override
174174
public Enumeration<String> getHeaderNames() {
175-
throw new UnsupportedOperationException("Not supported yet.");
175+
return Collections.enumeration(headers.keySet());
176176
}
177177

178178
@Override

0 commit comments

Comments
 (0)