-
Notifications
You must be signed in to change notification settings - Fork 598
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): validate XML during deserialization (#5991)
- Loading branch information
Showing
2 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import type { SerdeContext } from "@smithy/types"; | ||
import { toUtf8 } from "@smithy/util-utf8"; | ||
|
||
import { parseXmlBody } from "./parseXmlBody"; | ||
|
||
describe(parseXmlBody.name, () => { | ||
const context = { | ||
utf8Encoder: toUtf8, | ||
}; | ||
it("should parse xml", async () => { | ||
const xml = Buffer.from(`<?xml version="1.0" encoding="UTF-8"?> | ||
<ListAllMyBucketsResult> | ||
<Buckets> | ||
<Bucket> | ||
<CreationDate>timestamp</CreationDate> | ||
<Name>string</Name> | ||
</Bucket> | ||
</Buckets> | ||
<Owner> | ||
<DisplayName>string</DisplayName> | ||
<ID>string</ID> | ||
</Owner> | ||
</ListAllMyBucketsResult> | ||
`); | ||
const parsed = await parseXmlBody(xml, context as any as SerdeContext); | ||
expect(parsed).toEqual({ | ||
Buckets: { Bucket: { CreationDate: "timestamp", Name: "string" } }, | ||
Owner: { DisplayName: "string", ID: "string" }, | ||
}); | ||
}); | ||
|
||
it("should throw on incomplete xml", async () => { | ||
const xml = Buffer.from(`<?xml version="1.0" encoding="UTF-8"?> | ||
<ListAllMyBucketsResult> | ||
<Buckets> | ||
<Bucket> | ||
<CreationDate>timestamp</CreationDate> | ||
<Name>string</Name> | ||
</Bucket> | ||
</Buckets> | ||
<Owner> | ||
<DisplayName>string</DisplayName> | ||
<ID>string</ID> | ||
</Owner> | ||
`); | ||
const parsed = await parseXmlBody(xml, context as any as SerdeContext).catch((_) => _); | ||
expect(parsed.toString()).toEqual(`Error: Unclosed tag 'ListAllMyBucketsResult'.:2:1`); | ||
}); | ||
|
||
it("should throw on incomplete xml", async () => { | ||
const xml = Buffer.from(`<?xml version="1.0" encoding="UTF-8"?> | ||
<ListAllMyBucketsResult> | ||
<Buckets> | ||
<Bucket> | ||
<CreationDate>timestamp</Creatio | ||
`); | ||
const parsed = await parseXmlBody(xml, context as any as SerdeContext).catch((_) => _); | ||
expect(parsed.toString()).toEqual(`Error: Closing tag 'Creatio' doesn't have proper closing.:6:1`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters