This repository was archived by the owner on Jan 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathtest.parameterizeQuery.js
82 lines (70 loc) · 2.51 KB
/
test.parameterizeQuery.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* Copyright (C) 2013 TopCoder Inc., All Rights Reserved.
*
* @version 1.0
* @author Sky_
*/
"use strict";
var assert = require('chai').assert;
var async = require('async');
/*global describe, it, before, beforeEach, after, afterEach */
/*jslint node: true, stupid: true */
describe('Test parameterizeQuery', function () {
var api;
beforeEach(function (done) {
api = {
log: function () {
return null;
}
};
async.series([
function (cb) {
require('../initializers/helper').helper(api, cb);
}, function (cb) {
require('../initializers/dataAccess').dataAccess(api, cb);
}, function (cb) {
api.dataAccess._start(api, cb);
}
], done);
});
it('should parametrize query#1', function (done) {
var query = "select * from table where a = @a@",
params = { a: 1 },
expected = "select * from table where a = 1";
api.dataAccess._parameterizeQuery(query, params, function (err, q) {
assert.ifError(err);
assert.equal(expected, q);
done();
});
});
it('should parametrize query#2', function (done) {
var query = "select * from table where a = @a@ and b = @b@ and c = @a@",
params = { a: 1, b: 2 },
expected = "select * from table where a = 1 and b = 2 and c = 1";
api.dataAccess._parameterizeQuery(query, params, function (err, q) {
assert.ifError(err);
assert.equal(expected, q);
done();
});
});
it('should parametrize query#3 (missing parameter)', function (done) {
var query = "select * from table where a = @a@ and b = @b@ and c = @c@",
params = { a: 1, b: 2 },
expected = "select * from table where a = 1 and b = 2 and c = ";
api.dataAccess._parameterizeQuery(query, params, function (err, q) {
assert.ifError(err);
assert.equal(expected, q);
done();
});
});
it('should parametrize query (sql injection)', function (done) {
var query = "select * from table where a LIKE '@a@'",
params = { a: "'sql injection" },
expected = "select * from table where a LIKE '''sql injection'";
api.dataAccess._parameterizeQuery(query, params, function (err, q) {
assert.ifError(err);
assert.equal(expected, q);
done();
});
});
});