Skip to content

Commit e1ecdb5

Browse files
committed
multipart boundary validation tests
1 parent 2625112 commit e1ecdb5

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/Multipart.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,30 @@ describe("Multipart", function () {
2727
expect(new TextDecoder().decode(multipart.boundary)).to.equal("empty-boundary");
2828
expect(multipart.mediaType).to.equal("multipart/mixed");
2929
});
30+
31+
it("should accept only valid boundaries", function () {
32+
expect(() => new Multipart([], "")).to.throw(RangeError, "Invalid boundary");
33+
expect(() => new Multipart([], " ")).to.throw(RangeError, "Invalid boundary");
34+
expect(() => new Multipart([], "a ")).to.throw(RangeError, "Invalid boundary");
35+
expect(() => new Multipart([], "0123456789".repeat(7) + "0")).to.throw(RangeError, "Invalid boundary");
36+
expect(() => new Multipart([], "foo!bar")).to.throw(RangeError, "Invalid boundary");
37+
38+
expect(() => new Multipart([], "a")).to.not.throw();
39+
expect(() => new Multipart([], "0123456789".repeat(7))).to.not.throw();
40+
expect(() => new Multipart([], "foo bar")).to.not.throw();
41+
expect(() => new Multipart([], "foo'bar")).to.not.throw();
42+
expect(() => new Multipart([], "foo(bar")).to.not.throw();
43+
expect(() => new Multipart([], "foo)bar")).to.not.throw();
44+
expect(() => new Multipart([], "foo+bar")).to.not.throw();
45+
expect(() => new Multipart([], "foo_bar")).to.not.throw();
46+
expect(() => new Multipart([], "foo,bar")).to.not.throw();
47+
expect(() => new Multipart([], "foo-bar")).to.not.throw();
48+
expect(() => new Multipart([], "foo.bar")).to.not.throw();
49+
expect(() => new Multipart([], "foo/bar")).to.not.throw();
50+
expect(() => new Multipart([], "foo:bar")).to.not.throw();
51+
expect(() => new Multipart([], "foo=bar")).to.not.throw();
52+
expect(() => new Multipart([], "foo?bar")).to.not.throw();
53+
});
3054
});
3155

3256
describe("parse", function () {

0 commit comments

Comments
 (0)