Test cases for "If" header checks

Hi.

Below is a test script (for Microsoft's XMLHTTPRequest component) that 
tests various forms of "If" headers.

Basically it does some sanity checks first, and then tries the new 
syntax allowing comma-separated lists (or multiple headers).

Of the servers I tested, none supported the new format (not 
surprisingly), but most (*) replied with 400 (bad request). This means 
clients can test that, and there doesn't seem to be any need for a new 
compliance class just for this use case.

Best regards, Julian

(* I notified the maintainers of the other two servers, one of which 
happens to be myself)

--

var req = new ActiveXObject ("MSXML2.ServerXMLHTTP");

if (WScript.Arguments.length == 0) {
   WScript.Echo("Test case If header eval");
   WScript.Echo("Usage: cscript if_fail.js URI {username} {password}");
   WScript.Quit(2);
}

var uri = WScript.Arguments(0);
var user = null;
var pwd = null;

function dumpResponse(r) {
   WScript.Echo(r.status);
   WScript.Echo(r.getAllResponseHeaders());
   WScript.Echo(r.responseText);
}


if (WScript.Arguments.length > 1) {
   user = WScript.Arguments(1);
}

if (WScript.Arguments.length > 2) {
   pwd = WScript.Arguments(2);
}

var x = 1;

function testPut(ifheader, desc) {

   WScript.Echo("\n\n\nTest case " + x + ", If header: " + ifheader);
   WScript.Echo("(" + desc + ")");
   req.open("PUT", uri, false, user, pwd);
   if (ifheader != null) req.setRequestHeader("If", ifheader);
   req.send("test case " + x);
   dumpResponse(req);
   x += 1;
}


// delete content
WScript.Echo("DELETE " + uri);
req.open("DELETE", uri, false, user, pwd);
req.send("foobar");
dumpResponse(req);

testPut(null, "initial content");
if (req.status < 200 || req.status >= 300) {
   WScript.Echo("unexpected status upon PUT");
   WScript.Quit(2);
}

testPut("(<DAV:no-lock>)", "const false");
if (req.status != 412) {
   WScript.Echo("unexpected status upon PUT");
}

testPut("(Not <DAV:no-lock>)", "const true");
if (req.status != 204 && req.status != 200) {
   WScript.Echo("unexpected status upon PUT");
}

testPut("(<DAV:no-lock> Not <DAV:no-lock>)", "const false");
if (req.status != 412) {
   WScript.Echo("unexpected status upon PUT");
}

testPut("(<DAV:no-lock>), (Not <DAV:no-lock>)", "const true using comma 
notation");
if (req.status == 200 || req.status == 204) {
   WScript.Echo("Server seems to understand ',' in If-List as per 
RFC2518bis");
}
else if (req.status == 400) {
   WScript.Echo("Server seems not to understand ',' in If-List as per 
RFC2518bis, rejecting the request with 400");
}
else {
   WScript.Echo("unexpected status upon PUT");
}

testPut("(Not <DAV:no-lock>), (Not <DAV:no-lock>)", "const false using 
comma notation");
if (req.status == 412) {
   WScript.Echo("Server seems to understand ',' in If-List as per 
RFC2518bis");
}
else if (req.status == 400) {
   WScript.Echo("Server seems not to understand ',' in If-List as per 
RFC2518bis, rejecting the request with 400");
}
else {
   WScript.Echo("unexpected status upon PUT");
}

Received on Saturday, 22 October 2005 19:45:47 UTC