Bug 792321 - Check max values of MMS parameters in sendRequest. r=vyang a=leo+

This commit is contained in:
Chia-hung Tai 2012-12-06 18:44:54 +08:00
Родитель 116352d107
Коммит 80e551c5a3
4 изменённых файлов: 231 добавлений и 3 удалений

Просмотреть файл

@ -431,6 +431,83 @@ XPCOMUtils.defineLazyGetter(this, "gMmsTransactionHelper", function () {
releaseMmsConnectionAndCallback(0, null);
}
}).bind(this, method, url, istream, callback));
},
/**
* Count number of recipients(to, cc, bcc fields).
*
* @param recipients
* The recipients in MMS message object.
* @return the number of recipients
* @see OMA-TS-MMS_CONF-V1_3-20110511-C section 10.2.5
*/
countRecipients: function countRecipients(recipients) {
if (recipients && recipients.address) {
return 1;
}
let totalRecipients = 0;
if (!Array.isArray(recipients)) {
return 0;
}
totalRecipients += recipients.length;
for (let ix = 0; ix < recipients.length; ++ix) {
if (recipients[ix].address.length > MMS.MMS_MAX_LENGTH_RECIPIENT) {
throw new Error("MMS_MAX_LENGTH_RECIPIENT error");
}
if (recipients[ix].type === "email") {
let found = recipients[ix].address.indexOf("<");
let lenMailbox = recipients[ix].address.length - found;
if(lenMailbox > MMS.MMS_MAX_LENGTH_MAILBOX_PORTION) {
throw new Error("MMS_MAX_LENGTH_MAILBOX_PORTION error");
}
}
}
return totalRecipients;
},
/**
* Check maximum values of MMS parameters.
*
* @param msg
* The MMS message object.
* @return true if the lengths are less than the maximum values of MMS
* parameters.
* @see OMA-TS-MMS_CONF-V1_3-20110511-C section 10.2.5
*/
checkMaxValuesParameters: function checkMaxValuesParameters(msg) {
let subject = msg.headers["subject"];
if (subject && subject.length > MMS.MMS_MAX_LENGTH_SUBJECT) {
return false;
}
let totalRecipients = 0;
try {
totalRecipients += this.countRecipients(msg.headers["to"]);
totalRecipients += this.countRecipients(msg.headers["cc"]);
totalRecipients += this.countRecipients(msg.headers["bcc"]);
} catch (ex) {
debug("Exception caught : " + ex);
return false;
}
if (totalRecipients < 1 ||
totalRecipients > MMS.MMS_MAX_TOTAL_RECIPIENTS) {
return false;
}
if (!Array.isArray(msg.parts)) {
return true;
}
for (let i = 0; i < msg.parts.length; i++) {
if (msg.parts[i].headers["content-type"] &&
msg.parts[i].headers["content-type"].params) {
let name = msg.parts[i].headers["content-type"].params["name"];
if (name && name.length > MMS.MMS_MAX_LENGTH_NAME_CONTENT_TYPE) {
return false;
}
}
}
return true;
}
};
});
@ -556,6 +633,7 @@ RetrieveTransaction.prototype = {
/**
* SendTransaction.
* Class for sending M-Send.req to MMSC
* @throws Error("Check max values parameters fail.")
*/
function SendTransaction(msg) {
msg.headers["x-mms-message-type"] = MMS.MMS_PDU_TYPE_SEND_REQ;
@ -576,9 +654,11 @@ function SendTransaction(msg) {
msg.headers["x-mms-read-report"] = true;
msg.headers["x-mms-delivery-report"] = true;
// TODO: bug 792321 - MMSCONF-GEN-C-003: Support for maximum values for MMS
// parameters
if (!gMmsTransactionHelper.checkMaxValuesParameters(msg)) {
//We should notify end user that the header format is wrong.
debug("Check max values parameters fail.");
throw new Error("Check max values parameters fail.");
}
let messageSize = 0;
if (msg.content) {

Просмотреть файл

@ -94,6 +94,14 @@ this.MMS_PDU_STATUS_INDETERMINATE = 133;
this.MMS_PDU_STATUS_FORWARDED = 134;
this.MMS_PDU_STATUS_UNREACHABLE = 135;
// Maximum Values of MMS Parameters
// @see OMA-TS-MMS_CONF-V1_3-20110511-C 10.2.5
this.MMS_MAX_LENGTH_SUBJECT = 40;
this.MMS_MAX_LENGTH_RECIPIENT = 312;
this.MMS_MAX_TOTAL_RECIPIENTS = 20;
this.MMS_MAX_LENGTH_NAME_CONTENT_TYPE = 40;
this.MMS_MAX_LENGTH_MAILBOX_PORTION = 256;
this.ALL_CONST_SYMBOLS = undefined; // We want ALL_CONST_SYMBOLS to be exported.
this.ALL_CONST_SYMBOLS = Object.keys(this);

Просмотреть файл

@ -0,0 +1,139 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
function newMmsTransactionHelper() {
let MMS_Service = {};
subscriptLoader.loadSubScript("resource://gre/components/MmsService.js", MMS_Service);
MMS_Service.debug = do_print;
return MMS_Service.gMmsTransactionHelper;
}
let CallFunc = newMmsTransactionHelper();
function run_test() {
run_next_test();
}
//
// Test target: checkMaxValuesParameters
//
//// Test Long Subject field ////
//// @see OMA-ETS-MMS_CON-V1_3-20080128-C 5.1.1.1.10 MMS-1.3-con-171 ////
add_test(function test_LongSubjectField() {
let msg = {};
msg.headers = {};
// Test for normal TextString
msg.headers["subject"] = "abcdefghijklmnopqrstuvwxyz0123456789/-+@?";
do_check_eq(CallFunc.checkMaxValuesParameters(msg), false);
run_next_test();
});
//// Test recipient field length
add_test(function test_LongRecipientField() {
let msg = {};
msg.headers = {};
msg.headers["to"] = [
{ address:
"abcdefghijklmnopqrstuvwxyz0123456789/-+@?" +
"abcdefghijklmnopqrstuvwxyz0123456789/-+@?" +
"abcdefghijklmnopqrstuvwxyz0123456789/-+@?" +
"abcdefghijklmnopqrstuvwxyz0123456789/-+@?" +
"abcdefghijklmnopqrstuvwxyz0123456789/-+@?" +
"abcdefghijklmnopqrstuvwxyz0123456789/-+@?" +
"abcdefghijklmnopqrstuvwxyz0123456789/-+@?" +
"abcdefghijklmnopqrstuvwxyz",
type: "PLMN" },
];
do_check_eq(CallFunc.checkMaxValuesParameters(msg), false);
run_next_test();
});
add_test(function test_checkMaxValuesParameters() {
let msg = {};
msg.headers = {};
msg.headers["cc"] = [
{ address: "+789", type: "PLMN" },
{ address: "+119", type: "num" },
{ address: "Joe2 User " +
"<abcdefghijklmnopqrstuvwxyz0123456789" +
"abcdefghijklmnopqrstuvwxyz0123456789@" +
"abcdefghijklmnopqrstuvwxyz0123456789" +
"abcdefghijklmnopqrstuvwxyz0123456789." +
"abcdefghijklmnopqrstuvwxyz0123456789" +
"abcdefghijklmnopqrstuvwxyz0123456789" +
"abcdefghijklmnopqrstuvwxyz0123456789->"
, type: "email" },
];
do_check_eq(CallFunc.checkMaxValuesParameters(msg), false);
run_next_test();
});
//// Test total recipient count over 20
add_test(function test_TotalRecipientCount() {
let msg = {};
msg.headers = {};
do_check_eq(CallFunc.checkMaxValuesParameters(msg), false);
msg.headers["to"] = [
{ address: "+123", type: "PLMN" },
{ address: "+456", type: "num" },
{ address: "Joe User <joe@user.org>", type: "email" },
{ address: "+123", type: "PLMN" },
{ address: "+456", type: "num" },
{ address: "Joe User <joe@user.org>", type: "email" },
{ address: "+123", type: "PLMN" },
];
msg.headers["cc"] = [
{ address: "+789", type: "PLMN" },
{ address: "+119", type: "num" },
{ address: "Joe2 User <joe2@user.org>", type: "email" },
{ address: "+789", type: "PLMN" },
{ address: "+119", type: "num" },
{ address: "Joe2 User <joe2@user.org>", type: "email" },
{ address: "+789", type: "PLMN" },
];
msg.headers["bcc"] = [
{ address: "+110", type: "num" },
{ address: "Joe3 User <joe2@user.org>", type: "email" },
{ address: "Joe2 User <joe2@user.org>", type: "email" },
{ address: "+789", type: "PLMN" },
{ address: "+119", type: "num" },
{ address: "Joe2 User <joe2@user.org>", type: "email" },
{ address: "+789", type: "PLMN" },
];
do_check_eq(CallFunc.checkMaxValuesParameters(msg), false);
run_next_test();
});
////Test name parameter in content-type field of multi-parts
add_test(function test_NameParameterInContentType() {
let msg = {};
msg.headers = {};
msg.headers["to"] = [
{ address: "Joe User <joe@user.org>", type: "email" },
];
let params = {};
params["name"] = "abcdefghijklmnopqrstuvwxyz0123456789/-+@?";
let headers = {};
headers["content-type"] = {
media: null,
params: params,
};
msg.parts = new Array(1);
msg.parts[0] = {
index: 0,
headers: headers,
content: null,
};
do_check_eq(CallFunc.checkMaxValuesParameters(msg), false);
run_next_test();
});

Просмотреть файл

@ -4,3 +4,4 @@ tail =
[test_wsp_pdu_helper.js]
[test_mms_pdu_helper.js]
[test_mms_service.js]