Skip to content

Commit 69f0e20

Browse files
authored
CloudEvents attribute names SHOULD NOT exceed 20 chars (#366)
As per spec [1], attribute names SHOULD NOT and not MUST NOT exceed 20 characters in length. [1] https://github.com/cloudevents/spec/blob/master/spec.md#attribute-naming-conventionthis Signed-off-by: Pierangelo Di Pilato <[email protected]>
1 parent e2b1310 commit 69f0e20

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

core/src/main/java/io/cloudevents/core/impl/BaseCloudEventBuilder.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import io.cloudevents.CloudEventExtension;
2424
import io.cloudevents.core.builder.CloudEventBuilder;
2525
import io.cloudevents.core.data.BytesCloudEventData;
26-
import io.cloudevents.rw.CloudEventContextWriter;
2726
import io.cloudevents.rw.CloudEventRWException;
2827

2928
import javax.annotation.Nonnull;
@@ -198,9 +197,6 @@ protected static IllegalStateException createMissingAttributeException(String at
198197
* @see <a href="https://github.com/cloudevents/spec/blob/master/spec.md#attribute-naming-convention">attribute-naming-convention</a>
199198
*/
200199
private static boolean isValidExtensionName(String name) {
201-
if(name.length() > 20){
202-
return false;
203-
}
204200
char[] chars = name.toCharArray();
205201
for (char c : chars)
206202
if (!isValidChar(c)) {

core/src/test/java/io/cloudevents/core/impl/BaseCloudEventBuilderTest.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package io.cloudevents.core.impl;
22

33
import static org.assertj.core.api.Assertions.assertThat;
4-
import static org.junit.jupiter.api.Assertions.*;
5-
6-
import org.junit.jupiter.api.Test;
4+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
import static org.junit.jupiter.api.Assertions.assertNotNull;
7+
import static org.junit.jupiter.api.Assertions.assertThrows;
8+
import static org.junit.jupiter.api.Assertions.assertTrue;
79

810
import io.cloudevents.CloudEvent;
911
import io.cloudevents.core.builder.CloudEventBuilder;
1012
import io.cloudevents.core.extensions.DistributedTracingExtension;
1113
import io.cloudevents.core.test.Data;
14+
import org.junit.jupiter.api.Test;
1215

1316
public class BaseCloudEventBuilderTest {
1417

@@ -48,17 +51,23 @@ public void copyAndRemoveMaterializedExtension() {
4851
}
4952

5053
@Test
51-
public void testLongExtensionName() {
52-
Exception exception = assertThrows(RuntimeException.class, () -> {
53-
CloudEvent cloudEvent = CloudEventBuilder.v1(Data.V1_WITH_JSON_DATA_WITH_EXT)
54+
public void testLongExtensionNameV1() {
55+
assertDoesNotThrow(() -> {
56+
CloudEventBuilder.v1(Data.V1_WITH_JSON_DATA_WITH_EXT)
5457
.withExtension("thisextensionnameistoolong", "")
5558
.build();
5659
});
57-
String expectedMessage = "Invalid extensions name: thisextensionnameistoolong";
58-
String actualMessage = exception.getMessage();
60+
}
5961

60-
assertTrue(actualMessage.contains(expectedMessage));
62+
@Test
63+
public void testLongExtensionNameV03() {
64+
assertDoesNotThrow(() -> {
65+
CloudEventBuilder.v03(Data.V1_WITH_JSON_DATA_WITH_EXT)
66+
.withExtension("thisextensionnameistoolong", "")
67+
.build();
68+
});
6169
}
70+
6271
@Test
6372
public void testInvalidExtensionName() {
6473
Exception exception = assertThrows(RuntimeException.class, () -> {

0 commit comments

Comments
 (0)