Index: trunk/phase3/tests/phpunit/includes/upload/UploadStashTest.php |
— | — | @@ -45,11 +45,35 @@ |
46 | 46 | |
47 | 47 | $stash->removeFile( $file->getFileKey() ); |
48 | 48 | } |
| 49 | + |
| 50 | + public function testValidRequest() { |
| 51 | + $request = new FauxRequest( array( 'wpFileKey' => 'foo') ); |
| 52 | + $this->assertFalse( UploadFromStash::isValidRequest($request), 'Check failure on bad wpFileKey' ); |
| 53 | + |
| 54 | + $request = new FauxRequest( array( 'wpSessionKey' => 'foo') ); |
| 55 | + $this->assertFalse( UploadFromStash::isValidRequest($request), 'Check failure on bad wpSessionKey' ); |
| 56 | + |
| 57 | + $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test') ); |
| 58 | + $this->assertTrue( UploadFromStash::isValidRequest($request), 'Check good wpFileKey' ); |
| 59 | + |
| 60 | + $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test') ); |
| 61 | + $this->assertTrue( UploadFromStash::isValidRequest($request), 'Check good wpSessionKey' ); |
| 62 | + |
| 63 | + $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test', 'wpSessionKey' => 'foo') ); |
| 64 | + $this->assertTrue( UploadFromStash::isValidRequest($request), 'Check key precedence' ); |
| 65 | + } |
| 66 | + |
| 67 | + |
49 | 68 | |
50 | 69 | public function tearDown() { |
51 | 70 | parent::tearDown(); |
52 | 71 | |
53 | | - unlink( $this->bug29408File . "." ); |
54 | | - |
| 72 | + if( file_exists( $this->bug29408File . "." ) ) { |
| 73 | + unlink( $this->bug29408File . "." ); |
| 74 | + } |
| 75 | + |
| 76 | + if( file_exists( $this->bug29408File ) ) { |
| 77 | + unlink( $this->bug29408File ); |
| 78 | + } |
55 | 79 | } |
56 | 80 | } |
Index: trunk/phase3/includes/upload/UploadFromStash.php |
— | — | @@ -38,7 +38,7 @@ |
39 | 39 | |
40 | 40 | public static function isValidKey( $key ) { |
41 | 41 | // this is checked in more detail in UploadStash |
42 | | - return preg_match( UploadStash::KEY_FORMAT_REGEX, $key ); |
| 42 | + return preg_match( UploadStash::KEY_FORMAT_REGEX, $key ) ? true : false; |
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
— | — | @@ -47,7 +47,10 @@ |
48 | 48 | * @return Boolean |
49 | 49 | */ |
50 | 50 | public static function isValidRequest( $request ) { |
51 | | - return self::isValidKey( $request->getText( 'wpFileKey' ) || $request->getText( 'wpSessionKey' ) ); |
| 51 | + // this passes wpSessionKey to getText() as a default when wpFileKey isn't set. |
| 52 | + // wpSessionKey has no default which guarantees failure if both are missing |
| 53 | + // (though that should have been caught earlier) |
| 54 | + return self::isValidKey( $request->getText( 'wpFileKey', $request->getText( 'wpSessionKey' ) ) ); |
52 | 55 | } |
53 | 56 | |
54 | 57 | public function initialize( $key, $name = 'upload_file' ) { |
— | — | @@ -74,12 +77,12 @@ |
75 | 78 | * @param $request WebRequest |
76 | 79 | */ |
77 | 80 | public function initializeFromRequest( &$request ) { |
78 | | - $fileKey = $request->getText( 'wpFileKey' ) || $request->getText( 'wpSessionKey' ); |
| 81 | + // sends wpSessionKey as a default when wpFileKey is missing |
| 82 | + $fileKey = $request->getText( 'wpFileKey', $request->getText( 'wpSessionKey' ) ); |
79 | 83 | |
80 | | - $desiredDestName = $request->getText( 'wpDestFile' ); |
81 | | - if( !$desiredDestName ) { |
82 | | - $desiredDestName = $request->getText( 'wpUploadFile' ) || $request->getText( 'filename' ); |
83 | | - } |
| 84 | + // chooses one of wpDestFile, wpUploadFile, filename in that order. |
| 85 | + $desiredDestName = $request->getText( 'wpDestFile', $request->getText( 'wpUploadFile', $request->getText( 'filename' ) ) ); |
| 86 | + |
84 | 87 | return $this->initialize( $fileKey, $desiredDestName ); |
85 | 88 | } |
86 | 89 | |
— | — | @@ -100,7 +103,7 @@ |
101 | 104 | * There is no need to stash the image twice |
102 | 105 | */ |
103 | 106 | public function stashFile( $key = null ) { |
104 | | - if ( !empty( $this->mLocalFile ) ) { |
| 107 | + if ( !$this->mLocalFile ) { |
105 | 108 | return $this->mLocalFile; |
106 | 109 | } |
107 | 110 | return parent::stashFile( $key ); |
Index: trunk/phase3/includes/upload/UploadStash.php |
— | — | @@ -416,7 +416,7 @@ |
417 | 417 | $res = $dbr->select( |
418 | 418 | 'uploadstash', |
419 | 419 | 'us_key', |
420 | | - array( 'us_key' => $key ), |
| 420 | + array( 'us_user' => $this->userId ), |
421 | 421 | __METHOD__ |
422 | 422 | ); |
423 | 423 | |