-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for the OPTIONS method (v2)
- Loading branch information
1 parent
9ce23d1
commit 6e5981a
Showing
6 changed files
with
121 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,36 @@ | ||
import { TestCallback, TestInfo } from '../Type' | ||
import { v2 } from '../../../../lib/index.js' | ||
|
||
export function starter(server : v2.WebDAVServer, info : TestInfo, isValid : TestCallback, name : string, expect : string[], reject : string[], callback : (allowHeader ?: string[]) => void) : void | ||
{ | ||
server.rootFileSystem.addSubTree(info.ctx, { | ||
'folder': v2.ResourceType.Directory, | ||
'file': v2.ResourceType.File, | ||
'hybrid': v2.ResourceType.Hybrid, | ||
'noResource': v2.ResourceType.NoResource, | ||
}, (e) => { | ||
if(e) return isValid(false, 'Cannot call "addSubTree(...)".', e); | ||
|
||
info.req({ | ||
url: 'http://localhost:' + info.port + '/' + name, | ||
method: 'OPTIONS' | ||
}, v2.HTTPCodes.OK, (req) => { | ||
if(!req.headers.allow) | ||
return isValid(false, 'No "Allow" header returned in the response of the OPTIONS, but expected one.', JSON.stringify(req.headers, null, 4)); | ||
|
||
const allow = req.headers.allow.split(',').map((s) => s.trim().toLowerCase()); | ||
reject = reject.map((s) => s.trim().toLowerCase()); | ||
expect = expect.map((s) => s.trim().toLowerCase()); | ||
|
||
const rejected = reject.filter((r) => allow.some((a) => a === r)); | ||
if(rejected.length > 0) | ||
return isValid(false, 'Forbidden methods for resource present in the "Allow" header in the response.', rejected.toString()); | ||
|
||
const expected = expect.filter((r) => !allow.some((a) => a === r)); | ||
if(expected.length > 0) | ||
return isValid(false, 'All expected methods are not present in the "Allow" header in the response.', expected.toString()); | ||
|
||
callback(allow); | ||
}) | ||
}) | ||
} |
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,17 @@ | ||
import { Test } from '../Type' | ||
import { v2 } from '../../../../lib/index.js' | ||
import { starter } from './.createFiles' | ||
|
||
export default ((info, isValid) => | ||
{ | ||
const server = info.init(1); | ||
|
||
starter(server, info, isValid, 'folder', [ | ||
'COPY', 'DELETE', 'LOCK', 'MOVE', 'PROPFIND', 'PROPPATCH', 'UNLOCK' | ||
], [ | ||
'MKCOL', 'PUT', 'POST', 'GET', 'HEAD' | ||
], () => { | ||
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,17 @@ | ||
import { Test } from '../Type' | ||
import { v2 } from '../../../../lib/index.js' | ||
import { starter } from './.createFiles' | ||
|
||
export default ((info, isValid) => | ||
{ | ||
const server = info.init(1); | ||
|
||
starter(server, info, isValid, 'file', [ | ||
'GET', 'PUT', 'POST', 'COPY', 'DELETE', 'HEAD', 'LOCK', 'MOVE', 'PROPFIND', 'PROPPATCH', 'UNLOCK' | ||
], [ | ||
'MKCOL' | ||
], () => { | ||
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,17 @@ | ||
import { Test } from '../Type' | ||
import { v2 } from '../../../../lib/index.js' | ||
import { starter } from './.createFiles' | ||
|
||
export default ((info, isValid) => | ||
{ | ||
const server = info.init(1); | ||
|
||
starter(server, info, isValid, 'hybrid', [ | ||
'GET', 'PUT', 'POST', 'COPY', 'DELETE', 'HEAD', 'LOCK', 'MOVE', 'PROPFIND', 'PROPPATCH', 'UNLOCK' | ||
], [ | ||
'MKCOL' | ||
], () => { | ||
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,17 @@ | ||
import { Test } from '../Type' | ||
import { v2 } from '../../../../lib/index.js' | ||
import { starter } from './.createFiles' | ||
|
||
export default ((info, isValid) => | ||
{ | ||
const server = info.init(1); | ||
|
||
starter(server, info, isValid, 'noResource', [ | ||
'COPY', 'DELETE', 'LOCK', 'MOVE', 'PROPFIND', 'PROPPATCH', 'UNLOCK' | ||
], [ | ||
'GET', 'PUT', 'POST', 'HEAD', 'MKCOL' | ||
], () => { | ||
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,17 @@ | ||
import { Test } from '../Type' | ||
import { v2 } from '../../../../lib/index.js' | ||
import { starter } from './.createFiles' | ||
|
||
export default ((info, isValid) => | ||
{ | ||
const server = info.init(1); | ||
|
||
starter(server, info, isValid, 'fileUndefined', [ | ||
'MKCOL', 'PUT', 'POST', 'LOCK' | ||
], [ | ||
'GET', 'COPY', 'DELETE', 'HEAD', 'MOVE', 'PROPFIND', 'PROPPATCH', 'UNLOCK' | ||
], () => { | ||
isValid(true); | ||
}) | ||
|
||
}) as Test; |