-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test for the MOVE and COPY methods [v2]
- Loading branch information
1 parent
5d5d3a2
commit 0c5e114
Showing
7 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,51 @@ | ||
import { TestCallback, TestInfo } from '../Type' | ||
import { v2 } from '../../../../lib/index.js' | ||
|
||
export function check(server : v2.WebDAVServer, info : TestInfo, isValid : TestCallback, path : string, mustExist : boolean, callback : () => void) : void | ||
{ | ||
info.req({ | ||
url: 'http://localhost:' + server.options.port + '/' + path, | ||
method: 'PROPFIND', | ||
headers: { | ||
Depth: 0 | ||
} | ||
}, mustExist ? v2.HTTPCodes.MultiStatus : v2.HTTPCodes.NotFound, () => { | ||
callback(); | ||
}) | ||
} | ||
|
||
export function starter(server : v2.WebDAVServer, info : TestInfo, isValid : TestCallback, method : string, from : string, to : string, overwrite : boolean, expectedStatusCode : number, callback ?: (server : v2.WebDAVServer) => void) : void | ||
{ | ||
server.rootFileSystem().addSubTree(v2.RequestContext.createExternal(server), { | ||
'emptyFolder1': v2.ResourceType.Directory, | ||
'folder1': { | ||
'emptyFolder2': v2.ResourceType.Directory, | ||
'file2': v2.ResourceType.File, | ||
'folder2': { | ||
'emptyFolder3': v2.ResourceType.Directory, | ||
'file3': v2.ResourceType.File | ||
}, | ||
'folder2x': { | ||
'emptyFolder3x': v2.ResourceType.Directory, | ||
'file3x': v2.ResourceType.File | ||
} | ||
}, | ||
'file1': v2.ResourceType.File | ||
}, (e) => { | ||
if(e) return isValid(false, 'Cannot call "addSubTree(...)".', e); | ||
|
||
info.req({ | ||
url: 'http://localhost:' + server.options.port + '/' + from, | ||
method, | ||
headers: { | ||
overwrite: overwrite ? 'T' : 'F', | ||
destination: '/' + to | ||
} | ||
}, expectedStatusCode, () => { | ||
if(!callback) | ||
isValid(true); | ||
else | ||
callback(server); | ||
}) | ||
}) | ||
} |
This file contains 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,30 @@ | ||
import { Test } from '../Type' | ||
import { v2 } from '../../../../lib/index.js' | ||
import { starter, check } from './.createFiles' | ||
|
||
export default ((info, isValid) => | ||
{ | ||
const server1 = info.init(6); | ||
|
||
starter(info.startServer(), info, isValid, 'COPY', 'folder1', 'folder1x', false, v2.HTTPCodes.Created, (s) => { | ||
check(s, info, isValid, 'folder1', true, () => { | ||
check(s, info, isValid, 'folder1x', true, () => { | ||
isValid(true); | ||
}) | ||
}) | ||
}); | ||
|
||
starter(info.startServer(), info, isValid, 'COPY', 'folder1/folder2x', 'folder1/folder2', false, v2.HTTPCodes.PreconditionFailed); | ||
starter(info.startServer(), info, isValid, 'COPY', 'folder1/folder2x', 'folder1/folder2', true, v2.HTTPCodes.NoContent, (s) => { | ||
check(s, info, isValid, 'folder1/folder2x', true, () => { | ||
check(s, info, isValid, 'folder1/folder2', true, () => { | ||
isValid(true); | ||
}) | ||
}) | ||
}); | ||
|
||
starter(info.startServer(), info, isValid, 'COPY', 'folder1', 'folder1', false, v2.HTTPCodes.Forbidden); | ||
starter(info.startServer(), info, isValid, 'COPY', 'folder1', 'folder1/folder1', false, v2.HTTPCodes.BadGateway); | ||
starter(info.startServer(), info, isValid, 'COPY', 'folder1', 'unmapped/folder1', false, v2.HTTPCodes.Conflict); | ||
|
||
}) as Test; |
This file contains 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,30 @@ | ||
import { Test } from '../Type' | ||
import { v2 } from '../../../../lib/index.js' | ||
import { starter, check } from './.createFiles' | ||
|
||
export default ((info, isValid) => | ||
{ | ||
const server1 = info.init(6); | ||
|
||
starter(info.startServer(), info, isValid, 'COPY', 'file1', 'file1_moved', false, v2.HTTPCodes.Created, (s) => { | ||
check(s, info, isValid, 'file1', true, () => { | ||
check(s, info, isValid, 'file1_moved', true, () => { | ||
isValid(true); | ||
}) | ||
}) | ||
}); | ||
|
||
starter(info.startServer(), info, isValid, 'COPY', 'file1', 'folder1/file2', false, v2.HTTPCodes.PreconditionFailed); | ||
starter(info.startServer(), info, isValid, 'COPY', 'file1', 'folder1/file2', true, v2.HTTPCodes.NoContent, (s) => { | ||
check(s, info, isValid, 'file1', true, () => { | ||
check(s, info, isValid, 'folder1/file2', true, () => { | ||
isValid(true); | ||
}) | ||
}) | ||
}); | ||
|
||
starter(info.startServer(), info, isValid, 'COPY', 'file1', 'file1', false, v2.HTTPCodes.Forbidden); | ||
starter(info.startServer(), info, isValid, 'COPY', 'file1', 'file1/file1', false, v2.HTTPCodes.BadGateway); | ||
starter(info.startServer(), info, isValid, 'COPY', 'file1', 'unmapped/file1', false, v2.HTTPCodes.Conflict); | ||
|
||
}) as Test; |
This file contains 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,21 @@ | ||
import { Test } from '../Type' | ||
import { v2 } from '../../../../lib/index.js' | ||
import { starter, check } from './.createFiles' | ||
|
||
function execute(info, isValid, overwrite : boolean) | ||
{ | ||
starter(info.startServer(), info, isValid, 'COPY', 'file1Undefined', 'file1_moved', overwrite, v2.HTTPCodes.NotFound); | ||
starter(info.startServer(), info, isValid, 'COPY', 'file1Undefined', 'folder1/file2', overwrite, v2.HTTPCodes.NotFound); | ||
starter(info.startServer(), info, isValid, 'COPY', 'file1Undefined', 'file1', overwrite, v2.HTTPCodes.NotFound); | ||
starter(info.startServer(), info, isValid, 'COPY', 'file1Undefined', 'file1/file1', overwrite, v2.HTTPCodes.NotFound); | ||
starter(info.startServer(), info, isValid, 'COPY', 'file1Undefined', 'unmapped/file1', overwrite, v2.HTTPCodes.NotFound); | ||
} | ||
|
||
export default ((info, isValid) => | ||
{ | ||
const server1 = info.init(5 * 2); | ||
|
||
execute(info, isValid, false); | ||
execute(info, isValid, true); | ||
|
||
}) as Test; |
This file contains 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,30 @@ | ||
import { Test } from '../Type' | ||
import { v2 } from '../../../../lib/index.js' | ||
import { starter, check } from './.createFiles' | ||
|
||
export default ((info, isValid) => | ||
{ | ||
const server1 = info.init(6); | ||
|
||
starter(info.startServer(), info, isValid, 'MOVE', 'folder1', 'folder1x', false, v2.HTTPCodes.Created, (s) => { | ||
check(s, info, isValid, 'folder1', false, () => { | ||
check(s, info, isValid, 'folder1x', true, () => { | ||
isValid(true); | ||
}) | ||
}) | ||
}); | ||
|
||
starter(info.startServer(), info, isValid, 'MOVE', 'folder1/folder2x', 'folder1/folder2', false, v2.HTTPCodes.PreconditionFailed); | ||
starter(info.startServer(), info, isValid, 'MOVE', 'folder1/folder2x', 'folder1/folder2', true, v2.HTTPCodes.NoContent, (s) => { | ||
check(s, info, isValid, 'folder1/folder2x', false, () => { | ||
check(s, info, isValid, 'folder1/folder2', true, () => { | ||
isValid(true); | ||
}) | ||
}) | ||
}); | ||
|
||
starter(info.startServer(), info, isValid, 'MOVE', 'folder1', 'folder1', false, v2.HTTPCodes.Forbidden); | ||
starter(info.startServer(), info, isValid, 'MOVE', 'folder1', 'folder1/folder1', false, v2.HTTPCodes.BadGateway); | ||
starter(info.startServer(), info, isValid, 'MOVE', 'folder1', 'unmapped/folder1', false, v2.HTTPCodes.Conflict); | ||
|
||
}) as Test; |
This file contains 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,30 @@ | ||
import { Test } from '../Type' | ||
import { v2 } from '../../../../lib/index.js' | ||
import { starter, check } from './.createFiles' | ||
|
||
export default ((info, isValid) => | ||
{ | ||
const server1 = info.init(6); | ||
|
||
starter(info.startServer(), info, isValid, 'MOVE', 'file1', 'file1_moved', false, v2.HTTPCodes.Created, (s) => { | ||
check(s, info, isValid, 'file1', false, () => { | ||
check(s, info, isValid, 'file1_moved', true, () => { | ||
isValid(true); | ||
}) | ||
}) | ||
}); | ||
|
||
starter(info.startServer(), info, isValid, 'MOVE', 'file1', 'folder1/file2', false, v2.HTTPCodes.PreconditionFailed); | ||
starter(info.startServer(), info, isValid, 'MOVE', 'file1', 'folder1/file2', true, v2.HTTPCodes.NoContent, (s) => { | ||
check(s, info, isValid, 'file1', false, () => { | ||
check(s, info, isValid, 'folder1/file2', true, () => { | ||
isValid(true); | ||
}) | ||
}) | ||
}); | ||
|
||
starter(info.startServer(), info, isValid, 'MOVE', 'file1', 'file1', false, v2.HTTPCodes.Forbidden); | ||
starter(info.startServer(), info, isValid, 'MOVE', 'file1', 'file1/file1', false, v2.HTTPCodes.BadGateway); | ||
starter(info.startServer(), info, isValid, 'MOVE', 'file1', 'unmapped/file1', false, v2.HTTPCodes.Conflict); | ||
|
||
}) as Test; |
This file contains 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,21 @@ | ||
import { Test } from '../Type' | ||
import { v2 } from '../../../../lib/index.js' | ||
import { starter, check } from './.createFiles' | ||
|
||
function execute(info, isValid, overwrite : boolean) | ||
{ | ||
starter(info.startServer(), info, isValid, 'MOVE', 'file1Undefined', 'file1_moved', overwrite, v2.HTTPCodes.NotFound); | ||
starter(info.startServer(), info, isValid, 'MOVE', 'file1Undefined', 'folder1/file2', overwrite, v2.HTTPCodes.NotFound); | ||
starter(info.startServer(), info, isValid, 'MOVE', 'file1Undefined', 'file1', overwrite, v2.HTTPCodes.NotFound); | ||
starter(info.startServer(), info, isValid, 'MOVE', 'file1Undefined', 'file1/file1', overwrite, v2.HTTPCodes.NotFound); | ||
starter(info.startServer(), info, isValid, 'MOVE', 'file1Undefined', 'unmapped/file1', overwrite, v2.HTTPCodes.NotFound); | ||
} | ||
|
||
export default ((info, isValid) => | ||
{ | ||
const server1 = info.init(5 * 2); | ||
|
||
execute(info, isValid, false); | ||
execute(info, isValid, true); | ||
|
||
}) as Test; |