| | 153 | /** |
| | 154 | * @dataProvider file_path_provider |
| | 155 | */ |
| | 156 | function test_validate_file( $result, $allowed_files, $expected ) { |
| | 157 | $this->assertEquals( validate_file( '../foo/foo.txt' ), 1 ); |
| | 158 | $this->assertEquals( $expected, validate_file( $result, $allowed_files ) ); |
| | 159 | } |
| | 160 | |
| | 161 | function file_path_provider() { |
| | 162 | return array( |
| | 163 | array( '../foo/foo.txt', array(), 1 ), |
| | 164 | array( '../foo.txt', array(), 1 ), |
| | 165 | array( '../foo.bar', array(), 1 ), |
| | 166 | array( 'foo/bar/foo.txt', array(), 0 ), |
| | 167 | array( 'FOO/foo.txt', array(), 0 ), |
| | 168 | array( 'C:/WINDOWS/system32', array(), 2 ), |
| | 169 | array( './FOO/foo.txt', array(), 1 ), |
| | 170 | array( '/FOO/notallowed.txt', array( '/FOO/allowed.txt' ), 3 ), |
| | 171 | ); |
| | 172 | } |
| | 173 | |