|
| 1 | +// --- stubs --- |
| 2 | + |
| 3 | +class Data { |
| 4 | + init<S>(_ elements: S) {} |
| 5 | +} |
| 6 | + |
| 7 | +struct URL { |
| 8 | + init?(string: String) {} |
| 9 | +} |
| 10 | + |
| 11 | +extension String { |
| 12 | + init(contentsOf: URL) { |
| 13 | + let data = "" |
| 14 | + self.init(data) |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +class XMLNode { |
| 19 | + struct Options : OptionSet { |
| 20 | + let rawValue: Int |
| 21 | + static let nodeLoadExternalEntitiesAlways = XMLNode.Options(rawValue: 1 << 0) |
| 22 | + static let nodeLoadExternalEntitiesNever = XMLNode.Options(rawValue: 1 << 1) |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +class XMLElement {} |
| 27 | + |
| 28 | +class XMLDocument { |
| 29 | + init(contentsOf: URL, options: XMLNode.Options = []) {} |
| 30 | + init(data: Data, options: XMLNode.Options = []) {} |
| 31 | + init(rootElement: XMLElement?) {} |
| 32 | + init(xmlString: String, options: XMLNode.Options = []) {} |
| 33 | +} |
| 34 | + |
| 35 | +// --- tests --- |
| 36 | + |
| 37 | +func testUrl() { |
| 38 | + let remoteString = String(contentsOf: URL(string: "http://example.com/")!) |
| 39 | + let remoteUrl = URL(string: remoteString)! |
| 40 | + let _ = XMLDocument(contentsOf: remoteUrl, options: [.nodeLoadExternalEntitiesAlways]) // $ hasXXE=38 |
| 41 | +} |
| 42 | + |
| 43 | +func testUrlSafeImplicit() { |
| 44 | + let remoteString = String(contentsOf: URL(string: "http://example.com/")!) |
| 45 | + let remoteUrl = URL(string: remoteString)! |
| 46 | + let _ = XMLDocument(contentsOf: remoteUrl, options: []) // NO XXE: document doesn't enable external entities |
| 47 | +} |
| 48 | + |
| 49 | +func testUrlSafeExplicit() { |
| 50 | + let remoteString = String(contentsOf: URL(string: "http://example.com/")!) |
| 51 | + let remoteUrl = URL(string: remoteString)! |
| 52 | + let _ = XMLDocument(contentsOf: remoteUrl, options: [.nodeLoadExternalEntitiesNever]) // NO XXE: document disables external entities |
| 53 | +} |
| 54 | + |
| 55 | +func testData() { |
| 56 | + let remoteString = String(contentsOf: URL(string: "http://example.com/")!) |
| 57 | + let remoteData = Data(remoteString) |
| 58 | + let _ = XMLDocument(data: remoteData, options: [.nodeLoadExternalEntitiesAlways]) // $ hasXXE=56 |
| 59 | +} |
| 60 | + |
| 61 | +func testDataSafeImplicit() { |
| 62 | + let remoteString = String(contentsOf: URL(string: "http://example.com/")!) |
| 63 | + let remoteData = Data(remoteString) |
| 64 | + let _ = XMLDocument(data: remoteData, options: []) // NO XXE: document doesn't enable external entities |
| 65 | +} |
| 66 | + |
| 67 | +func testDataSafeExplicit() { |
| 68 | + let remoteString = String(contentsOf: URL(string: "http://example.com/")!) |
| 69 | + let remoteData = Data(remoteString) |
| 70 | + let _ = XMLDocument(data: remoteData, options: [.nodeLoadExternalEntitiesNever]) // NO XXE: document disables external entities |
| 71 | +} |
| 72 | + |
| 73 | +func testString() { |
| 74 | + let remoteString = String(contentsOf: URL(string: "http://example.com/")!) |
| 75 | + let _ = XMLDocument(xmlString: remoteString, options: [.nodeLoadExternalEntitiesAlways]) // $ hasXXE=74 |
| 76 | +} |
| 77 | + |
| 78 | +func testStringSafeImplicit() { |
| 79 | + let remoteString = String(contentsOf: URL(string: "http://example.com/")!) |
| 80 | + let _ = XMLDocument(xmlString: remoteString, options: []) // NO XXE: document doesn't enable external entities |
| 81 | +} |
| 82 | + |
| 83 | +func testStringSafeExplicit() { |
| 84 | + let remoteString = String(contentsOf: URL(string: "http://example.com/")!) |
| 85 | + let _ = XMLDocument(xmlString: remoteString, options: [.nodeLoadExternalEntitiesNever]) // NO XXE: document disables external entities |
| 86 | +} |
0 commit comments