Skip to content

Commit cfdbaf6

Browse files
committed
Merge branch 'feature/better-handling-of-untrusted-triggered-errors'
2 parents d953f64 + afd7475 commit cfdbaf6

File tree

10 files changed

+647
-74
lines changed

10 files changed

+647
-74
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@
44
test/composer.lock
55
test/vendor
66
.unfinished
7+
.vscode
8+
9+
# using the docker-compose example will auto-extract some embedded images. ignore.
10+
test/fixtures/id3v2_artist_album_title_cover.jpg
11+
test/fixtures/tagged_with_cover.jpg

CHANGELOG.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Changelog
22
=========
33

4+
1.37 2022-10-27 * Errors now return an HTTP status code 500 by default.
5+
* If the error is due to no content, or a bad URL passed to
6+
?dir=, then it will be a 404 and no information about
7+
the server paths will be returned in the output. Thanks
8+
to @EdwarDDay for this security suggestion. (#64)
9+
* fix nasty bug where paths were sometimes invalid due to
10+
mishandling of trailing slashes (#55)
11+
412
1.36 2022-08-25 * Fix bug where podcasts with autosaved cover art would end up
513
with duplicated iTunes metadata tags. Thanks once again to
614
@EdwarDDay for the bug report.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[![Testing dir2cast](https://github.com/ben-xo/dir2cast/actions/workflows/testing.yml/badge.svg)](https://github.com/ben-xo/dir2cast/actions/workflows/testing.yml)
22

33

4-
dir2cast by Ben XO v1.36 (2022-08-25)
4+
dir2cast by Ben XO v1.37 (2022-10-27)
55
================================================================================
66

77
https://github.com/ben-xo/dir2cast/

dir2cast.php

Lines changed: 136 additions & 59 deletions
Large diffs are not rendered by default.

docker-compose/nginx/default.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ server {
88
# Don't allow downloading of dir2cast.ini, as it may contain sensitive
99
# info such as the refresh password. Also, don't allow downloading of
1010
# dir2cast.php, for security and privacy reasons.
11-
location ~ /dir2cast\.(ini|php)$ {
11+
location ~ \.(ini|php)$ {
1212
return 404;
1313
}
1414

test/FakeGetoptTest.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php declare(strict_types=1);
2+
3+
use PHPUnit\Framework\TestCase;
4+
5+
final class FakeGetoptTest extends TestCase
6+
{
7+
public function test_fake_getopt_no_args()
8+
{
9+
$this->assertEquals(
10+
fake_getopt(array('php', '--halp'), '', array()),
11+
array()
12+
);
13+
$this->assertEquals(
14+
fake_getopt(array('php'), '', array()),
15+
array()
16+
);
17+
}
18+
public function test_fake_getopt_no_match()
19+
{
20+
$this->assertEquals(
21+
fake_getopt(array('php', '--halp'), '', array('help')),
22+
array()
23+
);
24+
$this->assertEquals(
25+
fake_getopt(array('php'), '', array('help')),
26+
array()
27+
);
28+
}
29+
30+
public function test_fake_getopt_bool_arg()
31+
{
32+
$this->assertEquals(
33+
fake_getopt(array('php', '--help'), '', array('help')),
34+
array('help' => false)
35+
);
36+
}
37+
public function test_fake_getopt_string_arg()
38+
{
39+
$this->assertEquals(
40+
fake_getopt(array('php', '--media-dir'), '', array('media-dir::')),
41+
array('media-dir' => '')
42+
);
43+
$this->assertEquals(
44+
fake_getopt(array('php', '--media-dir='), '', array('media-dir::')),
45+
array() // XXX: seems to be a bug in getopt
46+
);
47+
$this->assertEquals(
48+
fake_getopt(array('php', '--media-dir=test'), '', array('media-dir::')),
49+
array('media-dir' => 'test')
50+
);
51+
}
52+
public function test_fake_getopt_escaping()
53+
{
54+
$this->assertEquals(
55+
fake_getopt(array('php', "--media-dir= "), '', array('media-dir::')),
56+
array('media-dir' => ' ')
57+
);
58+
$this->assertEquals(
59+
fake_getopt(array('php', '--media-dir=""'), '', array('media-dir::')),
60+
array('media-dir' => '""')
61+
);
62+
$this->assertEquals(
63+
fake_getopt(array('php', "--media-dir=''"), '', array('media-dir::')),
64+
array('media-dir' => "''")
65+
);
66+
}
67+
public function test_fake_getopt_both_arg_types()
68+
{
69+
$this->assertEquals(
70+
fake_getopt(array('php', '--help', '--media-dir'), '', array('help', 'media-dir::')),
71+
array('help' => false, 'media-dir' => '')
72+
);
73+
}
74+
}

test/FourOhFourTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php declare(strict_types=1);
2+
3+
use PHPUnit\Framework\TestCase;
4+
5+
final class FourOhFourTest extends TestCase
6+
{
7+
public static function setUpBeforeClass(): void
8+
{
9+
prepare_testing_dir();
10+
}
11+
12+
public function test_non_existent_dir_prints_bare_error_CLI_case(): void
13+
{
14+
exec('php dir2cast.php --media-dir=dir2cast.ini', $output, $returncode);
15+
$this->assertEquals("Not Found: dir2cast.ini", implode("\n", $output));
16+
$this->assertEquals(254, $returncode); // 254 is -2
17+
}
18+
19+
public static function tearDownAfterClass(): void
20+
{
21+
chdir('..');
22+
}
23+
}

0 commit comments

Comments
 (0)