Skip to content

Commit 5d12557

Browse files
committed
Swift: Test for FileManager taint sources.
1 parent 4356d35 commit 5d12557

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// --- stubs ---
2+
3+
class NSObject {
4+
}
5+
6+
struct URL {
7+
}
8+
9+
struct URLResourceKey {
10+
}
11+
12+
struct Data {
13+
}
14+
15+
class FileManager : NSObject {
16+
struct DirectoryEnumerationOptions : OptionSet{
17+
let rawValue: Int
18+
}
19+
20+
func contentsOfDirectory(at url: URL, includingPropertyForKeys keys: [URLResourceKey]?, options mask: FileManager.DirectoryEnumerationOptions = []) throws -> [URL] { return [] }
21+
func contentsOfDirectory(atPath path: String) throws -> [String] { return [] }
22+
func directoryContents(atPath path: String) -> [Any]? { return [] } // returns array of NSString
23+
func subpathsOfDirectory(atPath path: String) throws -> [String] { return [] }
24+
func subpaths(atPath path: String) -> [String]? { return [] }
25+
26+
func destinationOfSymbolicLink(atPath path: String) throws -> String { return "" }
27+
func pathContentOfSymbolicLink(atPath path: String) -> String? { return "" }
28+
29+
func contents(atPath path: String) -> Data? { return nil }
30+
}
31+
32+
// --- tests ---
33+
34+
func testFileHandle(fm: FileManager, url: URL, path: String) {
35+
do
36+
{
37+
let contents1 = try fm.contentsOfDirectory(at: url, includingPropertyForKeys: nil) // SOURCE
38+
let content1 = contents1[0]
39+
let contents2 = try fm.contentsOfDirectory(atPath: path) // SOURCE
40+
let contents3 = fm.directoryContents(atPath: path)! // SOURCE
41+
42+
let subpaths1 = try fm.subpathsOfDirectory(atPath: path) // SOURCE
43+
let subpaths2 = fm.subpaths(atPath: path)! // SOURCE
44+
45+
let link1 = try fm.destinationOfSymbolicLink(atPath: path) // SOURCE
46+
let link2 = fm.pathContentOfSymbolicLink(atPath: path)! // SOURCE
47+
48+
let data = fm.contents(atPath: path)! // SOURCE
49+
} catch {
50+
// ...
51+
}
52+
}

0 commit comments

Comments
 (0)