-
-
Notifications
You must be signed in to change notification settings - Fork 3
image validation #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
image validation #27
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
43d56ed
image validation
YvarRavy 32b698a
vbump
YvarRavy 0e89c8e
add test and use full title of page to show on special page
YvarRavy c902c85
fix smw version
YvarRavy 2207df3
try and fix test
YvarRavy 941a2db
try and install gd
YvarRavy 7b36bfc
try and fix text
YvarRavy ee43dc5
add zlib
YvarRavy d0059b3
fix invalid yml
YvarRavy f256244
fix yml
YvarRavy 161a0ce
remove zlib
YvarRavy ae3e9d9
use make instead
YvarRavy 8e12997
use comma seperated
YvarRavy 082059f
changes to i18n
YvarRavy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,88 @@ | ||
| <?php | ||
|
|
||
| namespace SmartComments\Tests\Integration\Store; | ||
|
|
||
| use MediaWiki\Extension\SmartComments\Store\ImageSaver; | ||
| use MediaWiki\Extension\SmartComments\Hooks; | ||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| class ImageSaverTest extends TestCase { | ||
|
|
||
| /** | ||
| * @var \Title|\PHPUnit\Framework\MockObject\MockObject | ||
| */ | ||
| private $titleMock; | ||
|
|
||
| /** | ||
| * Set up the test environment | ||
| */ | ||
| protected function setUp(): void { | ||
| parent::setUp(); | ||
|
|
||
| $this->titleMock = $this->createMock( \Title::class ); | ||
| $this->titleMock->method( 'getId' )->willReturn( 123 ); | ||
|
|
||
| Hooks::$imageSaveDirectory = sys_get_temp_dir(); | ||
| } | ||
|
|
||
| /** | ||
| * Test that ImageSaver returns null for invalid XSS payload | ||
| */ | ||
| public function testInvalidXssPayload(): void { | ||
| $imageSaver = new ImageSaver( $this->titleMock ); | ||
|
|
||
| $invalidPayload = 'data:image/png;base64,PHNjcmlwdD5hbGVydCgneHNzJyk7PC9zY3JpcHQ+'; | ||
|
|
||
| $result = $imageSaver->save( $invalidPayload ); | ||
|
|
||
| $this->assertNull( $result, 'ImageSaver should return null for XSS payload' ); | ||
| } | ||
|
|
||
| /** | ||
| * Test that ImageSaver returns a filename for valid payload | ||
| */ | ||
| public function testValidPayload(): void { | ||
| $imageSaver = new ImageSaver( $this->titleMock ); | ||
|
|
||
| $validPayload = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII='; | ||
|
|
||
| $result = $imageSaver->save( $validPayload ); | ||
|
|
||
| $this->assertNotNull( $result, 'ImageSaver should return a filename for valid payload' ); | ||
|
|
||
| $filePath = Hooks::$imageSaveDirectory . '/' . $result; | ||
| $this->assertFileExists( $filePath, 'Image file should be created' ); | ||
|
|
||
| if ( file_exists( $filePath ) ) { | ||
| unlink( $filePath ); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Test that ImageSaver returns null for non-image data | ||
| */ | ||
| public function testNonImageData(): void { | ||
| $imageSaver = new ImageSaver( $this->titleMock ); | ||
|
|
||
| // Base64 encoded text that's not an image | ||
| $nonImagePayload = 'data:image/png;base64,SGVsbG8gV29ybGQ='; | ||
|
|
||
| $result = $imageSaver->save( $nonImagePayload ); | ||
|
|
||
| // Assert that the result is null for non-image data | ||
| $this->assertNull( $result, 'ImageSaver should return null for non-image data' ); | ||
| } | ||
|
|
||
| /** | ||
| * Test that ImageSaver returns null for unsupported image type | ||
| */ | ||
| public function testUnsupportedImageType(): void { | ||
| $imageSaver = new ImageSaver( $this->titleMock ); | ||
|
|
||
| $unsupportedTypePayload = 'data:image/webp;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII='; | ||
|
|
||
| $result = $imageSaver->save( $unsupportedTypePayload ); | ||
|
|
||
| $this->assertNull( $result, 'ImageSaver should return null for unsupported image type' ); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.