File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed
Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 99 * OF ANY KIND, either express or implied. See the License for the specific language
1010 * governing permissions and limitations under the License.
1111 */
12+ const NO_DEST_ERROR = {
13+ body : JSON . stringify ( { error : 'No destination provided.' } ) ,
14+ status : 400 ,
15+ } ;
16+
1217export default async function copyHelper ( req , daCtx ) {
1318 const formData = await req . formData ( ) ;
1419 if ( ! formData ) return { } ;
1520 const fullDest = formData . get ( 'destination' ) ;
21+ if ( ! fullDest ) return { error : NO_DEST_ERROR } ;
1622 const continuationToken = formData . get ( 'continuation-token' ) ;
1723 const lower = fullDest . slice ( 1 ) . toLowerCase ( ) ;
1824 const sanitized = lower . endsWith ( '/' ) ? lower . slice ( 0 , - 1 ) : lower ;
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import { hasPermission } from '../utils/auth.js';
1515
1616export default async function copyHandler ( { req, env, daCtx } ) {
1717 const details = await copyHelper ( req , daCtx ) ;
18+ if ( details . error ) return details . error ;
1819 if ( ! hasPermission ( daCtx , details . source , 'read' )
1920 || ! hasPermission ( daCtx , details . destination , 'write' ) ) return { status : 403 } ;
2021 return copyObject ( env , daCtx , details , false ) ;
Original file line number Diff line number Diff line change @@ -69,4 +69,30 @@ describe('Copy Route', () => {
6969 assert . strictEqual ( 'my/dest2.html' , copyCalled [ 0 ] . d . destination ) ;
7070 assert . strictEqual ( false , copyCalled [ 0 ] . m ) ;
7171 } ) ;
72+
73+ it ( 'Test copyHandler - no destination provided' , async ( ) => {
74+ const copyCalled = [ ] ;
75+ const copyObject = ( e , c , d , m ) => {
76+ copyCalled . push ( {
77+ e, c, d, m,
78+ } ) ;
79+ return { status : 200 } ;
80+ } ;
81+
82+ const copyHandler = await esmock ( '../../src/routes/copy.js' , {
83+ '../../src/storage/object/copy.js' : {
84+ default : copyObject ,
85+ } ,
86+ '../../src/utils/auth.js' : { hasPermission : ( ) => true } ,
87+ } ) ;
88+
89+ const formdata = new Map ( ) ;
90+ const req = {
91+ formData : ( ) => formdata ,
92+ } ;
93+
94+ const resp = await copyHandler ( { req, env : { } , daCtx : { key : 'my/src.html' } } ) ;
95+ assert . strictEqual ( 400 , resp . status ) ;
96+ assert . strictEqual ( copyCalled . length , 0 ) ;
97+ } ) ;
7298} ) ;
You can’t perform that action at this time.
0 commit comments