Skip to content

Commit 31627c2

Browse files
Added check for documented reserved SD-ID's
1 parent 9cbeb4f commit 31627c2

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/main/java/com/cloudbees/syslog/SDElement.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ public class SDElement implements Serializable {
3030

3131
private static final long serialVersionUID = 1L;
3232

33+
/**
34+
* Reserved SD-IDs as documented in <a href="https://www.rfc-editor.org/rfc/rfc5424.txt">RFC-5424</a>
35+
*/
36+
public static final String[] RESERVED_SDID = new String[]{
37+
"timeQuality",
38+
"tzKnown",
39+
"isSynced",
40+
"syncAccuracy"
41+
};
42+
3343
public SDElement(String sdID) {
3444
validateSDID(sdID);
3545
this.sdID = sdID;
@@ -131,6 +141,18 @@ private void validateSDID(String sdName) {
131141
if (sdName.contains("\"")) {
132142
throw new IllegalArgumentException("SD-ID cannot contain '\"'");
133143
}
144+
if (! sdName.contains("@")) {
145+
boolean found = false;
146+
for (String rn : RESERVED_SDID) {
147+
if (rn.equals(sdName)) {
148+
found = true;
149+
break;
150+
}
151+
}
152+
if (! found) {
153+
throw new IllegalArgumentException("SD-ID is not known registered SDID: " + sdName);
154+
}
155+
}
134156
}
135157

136158
}

src/test/java/com/cloudbees/syslog/SyslogMessageTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ public void testRfc5424FormatWithStructuredData() throws Exception {
8787
expected = "<14>1 2013-12-05T10:30:05.000Z myserver.example.com my_app - - [exampleSDID@32473 iut=\"3\" eventSource=\"Application\" eventID=\"1011\"][examplePriority@32473 class=\"high\"] a syslog message";
8888

8989
assertThat(actual, is(expected));
90-
9190
}
9291

9392
@Test

0 commit comments

Comments
 (0)