Bug 1848763 - update ntlm connection reset tests. r=necko-reviewers,valentin

Differential Revision: https://phabricator.services.mozilla.com/D187425
This commit is contained in:
sunil mayya 2023-09-13 22:38:58 +00:00
parent 856957c61d
commit 3dfa50a776

View File

@ -221,9 +221,12 @@ function connectionReset(metadata, response) {
authPrefix = authorization.substring(0, NTLM_PREFIX_LEN); authPrefix = authorization.substring(0, NTLM_PREFIX_LEN);
Assert.equal(NTLM_TYPE3_PREFIX, authPrefix, "Expecting a Type 3 message"); Assert.equal(NTLM_TYPE3_PREFIX, authPrefix, "Expecting a Type 3 message");
ntlmTypeTwoCount++; ntlmTypeTwoCount++;
response.finish(); try {
response.seizePower(); response.seizePower();
response.bodyOutPutStream.close(); response.finish();
} catch (e) {
Assert.ok(false, "unexpected exception" + e);
}
break; break;
default: default:
// Should not get any further requests on this channel // Should not get any further requests on this channel
@ -234,31 +237,32 @@ function connectionReset(metadata, response) {
} }
// //
// Reset the connection after a nogotiate message has been received // Reset the connection after a negotiate message has been received
// //
function connectionReset02(metadata, response) { function connectionReset02(metadata, response) {
var connectionNumber = httpserver.connectionNumber;
switch (requestsMade) { switch (requestsMade) {
case 0: case 0:
// Proxy - First request to the Proxy resppond with a 407 to start auth // Proxy - First request to the Proxy respond with a 407 to start auth
response.setStatusLine(metadata.httpVersion, 407, "Unauthorized"); response.setStatusLine(metadata.httpVersion, 407, "Unauthorized");
response.setHeader("Proxy-Authenticate", "NTLM", false); response.setHeader("Proxy-Authenticate", "NTLM", false);
Assert.equal(connectionNumber, httpserver.connectionNumber);
break; break;
case 1: case 1:
// eslint-disable-next-line no-fallthrough
default:
// Proxy - Expecting a type 1 negotiate message from the client // Proxy - Expecting a type 1 negotiate message from the client
Assert.equal(connectionNumber, httpserver.connectionNumber);
var authorization = metadata.getHeader("Proxy-Authorization"); var authorization = metadata.getHeader("Proxy-Authorization");
var authPrefix = authorization.substring(0, NTLM_PREFIX_LEN); var authPrefix = authorization.substring(0, NTLM_PREFIX_LEN);
Assert.equal(NTLM_TYPE1_PREFIX, authPrefix, "Expecting a Type 1 message"); Assert.equal(NTLM_TYPE1_PREFIX, authPrefix, "Expecting a Type 1 message");
ntlmTypeOneCount++; ntlmTypeOneCount++;
response.setStatusLine(metadata.httpVersion, 407, "Unauthorized"); try {
response.setHeader("Proxy-Authenticate", PROXY_CHALLENGE, false); response.seizePower();
response.finish(); response.finish();
response.seizePower(); } catch (e) {
response.bodyOutPutStream.close(); Assert.ok(false, "unexpected exception" + e);
break; }
default:
// Should not get any further requests on this channel
dump("ERROR: NTLM Proxy Authentication, connection should not be reused");
Assert.ok(false);
} }
requestsMade++; requestsMade++;
} }
@ -323,40 +327,82 @@ function setupTest(path, handler, requests, response, clearCache) {
}); });
} }
let ntlmTypeOneCount = 0; // The number of NTLM type one messages received
let exptTypeOneCount = 0; // The number of NTLM type one messages that should be received
let ntlmTypeTwoCount = 0; // The number of NTLM type two messages received
let exptTypeTwoCount = 0; // The number of NTLM type two messages that should received
// Happy code path // Happy code path
// Succesful proxy auth. // Successful proxy auth.
add_task(async function test_happy_path() { async function test_happy_path() {
dump("RUNNING TEST: test_happy_path"); dump("RUNNING TEST: test_happy_path");
await setupTest("/auth", successfulAuth, 3, 200, 1); await setupTest("/auth", successfulAuth, 3, 200, 1);
}); }
// Failed proxy authentication // Failed proxy authentication
add_task(async function test_failed_auth() { async function test_failed_auth() {
dump("RUNNING TEST:failed auth "); dump("RUNNING TEST:failed auth ");
await setupTest("/auth", failedAuth, 4, 407, 1); await setupTest("/auth", failedAuth, 4, 407, 1);
}); }
var ntlmTypeOneCount = 0; // The number of NTLM type one messages received
var exptTypeOneCount = 0; // The number of NTLM type one messages that should be received
var ntlmTypeTwoCount = 0; // The number of NTLM type two messages received
var exptTypeTwoCount = 0; // The number of NTLM type two messages that should received
// Test connection reset, after successful auth // Test connection reset, after successful auth
add_task(async function test_connection_reset() { async function test_connection_reset() {
dump("RUNNING TEST:connection reset "); dump("RUNNING TEST:connection reset ");
ntlmTypeOneCount = 0; ntlmTypeOneCount = 0;
ntlmTypeTwoCount = 0; ntlmTypeTwoCount = 0;
exptTypeOneCount = 1; exptTypeOneCount = 1;
exptTypeTwoCount = 1; exptTypeTwoCount = 1;
await setupTest("/auth", connectionReset, 2, 500, 1); await setupTest("/auth", connectionReset, 3, 500, 1);
}); }
// Test connection reset after sending a negotiate. // Test connection reset after sending a negotiate.
add_task(async function test_connection_reset02() { // Client should retry request using the same connection
async function test_connection_reset02() {
dump("RUNNING TEST:connection reset "); dump("RUNNING TEST:connection reset ");
ntlmTypeOneCount = 0; ntlmTypeOneCount = 0;
ntlmTypeTwoCount = 0; ntlmTypeTwoCount = 0;
exptTypeOneCount = 1; let maxRetryAttempt = 5;
exptTypeOneCount = maxRetryAttempt;
exptTypeTwoCount = 0; exptTypeTwoCount = 0;
await setupTest("/auth", connectionReset02, 1, 500, 1);
}); Services.prefs.setIntPref(
"network.http.request.max-attempts",
maxRetryAttempt
);
await setupTest("/auth", connectionReset02, maxRetryAttempt + 1, 500, 1);
}
add_task(
{ pref_set: [["network.auth.use_redirect_for_retries", false]] },
test_happy_path
);
add_task(
{ pref_set: [["network.auth.use_redirect_for_retries", false]] },
test_failed_auth
);
add_task(
{ pref_set: [["network.auth.use_redirect_for_retries", false]] },
test_connection_reset
);
add_task(
{ pref_set: [["network.auth.use_redirect_for_retries", false]] },
test_connection_reset02
);
add_task(
{ pref_set: [["network.auth.use_redirect_for_retries", true]] },
test_happy_path
);
add_task(
{ pref_set: [["network.auth.use_redirect_for_retries", true]] },
test_failed_auth
);
add_task(
{ pref_set: [["network.auth.use_redirect_for_retries", true]] },
test_connection_reset
);
add_task(
{ pref_set: [["network.auth.use_redirect_for_retries", true]] },
test_connection_reset02
);