|
| 1 | +require('./init'); |
| 2 | + |
| 3 | +var should = require('should'); |
| 4 | + |
| 5 | +var Post, db; |
| 6 | + |
| 7 | +describe('mssql connector', function () { |
| 8 | + |
| 9 | + before(function () { |
| 10 | + db = getDataSource(); |
| 11 | + |
| 12 | + Post = db.define('PostWithBoolean', { |
| 13 | + title: { type: String, length: 255, index: true }, |
| 14 | + content: { type: String }, |
| 15 | + approved: Boolean |
| 16 | + }); |
| 17 | + }); |
| 18 | + |
| 19 | + it('should run migration', function (done) { |
| 20 | + db.automigrate('PostWithBoolean', function () { |
| 21 | + done(); |
| 22 | + }); |
| 23 | + }); |
| 24 | + |
| 25 | + var post; |
| 26 | + it('should support boolean types with true value', function(done) { |
| 27 | + Post.create({title: 'T1', content: 'C1', approved: true}, function(err, p) { |
| 28 | + should.not.exists(err); |
| 29 | + post = p; |
| 30 | + Post.findById(p.id, function(err, p) { |
| 31 | + should.not.exists(err); |
| 32 | + p.should.have.property('approved', true); |
| 33 | + done(); |
| 34 | + }); |
| 35 | + }); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should support updating boolean types with false value', function(done) { |
| 39 | + Post.update({id: post.id}, {approved: false}, function(err) { |
| 40 | + should.not.exists(err); |
| 41 | + Post.findById(post.id, function(err, p) { |
| 42 | + should.not.exists(err); |
| 43 | + p.should.have.property('approved', false); |
| 44 | + done(); |
| 45 | + }); |
| 46 | + }); |
| 47 | + }); |
| 48 | + |
| 49 | + |
| 50 | + it('should support boolean types with false value', function(done) { |
| 51 | + Post.create({title: 'T2', content: 'C2', approved: false}, function(err, p) { |
| 52 | + should.not.exists(err); |
| 53 | + post = p; |
| 54 | + Post.findById(p.id, function(err, p) { |
| 55 | + should.not.exists(err); |
| 56 | + p.should.have.property('approved', false); |
| 57 | + done(); |
| 58 | + }); |
| 59 | + }); |
| 60 | + }); |
| 61 | + |
| 62 | + it('should single quote escape', function(done) { |
| 63 | + Post.create({title: "T2", content: "C,D", approved: false}, function(err, p) { |
| 64 | + should.not.exists(err); |
| 65 | + post = p; |
| 66 | + Post.findById(p.id, function(err, p) { |
| 67 | + should.not.exists(err); |
| 68 | + p.should.have.property('content', "C,D"); |
| 69 | + done(); |
| 70 | + }); |
| 71 | + }); |
| 72 | + }); |
| 73 | + |
| 74 | + it('should return the model instance for upsert', function(done) { |
| 75 | + Post.upsert({id: post.id, title: 'T2_new', content: 'C2_new', |
| 76 | + approved: true}, function(err, p) { |
| 77 | + p.should.have.property('id', post.id); |
| 78 | + p.should.have.property('title', 'T2_new'); |
| 79 | + p.should.have.property('content', 'C2_new'); |
| 80 | + p.should.have.property('approved', true); |
| 81 | + done(); |
| 82 | + }); |
| 83 | + }); |
| 84 | + |
| 85 | + it('should return the model instance for upsert when id is not present', |
| 86 | + function(done) { |
| 87 | + Post.upsert({title: 'T2_new', content: 'C2_new', approved: true}, |
| 88 | + function(err, p) { |
| 89 | + p.should.have.property('id'); |
| 90 | + p.should.have.property('title', 'T2_new'); |
| 91 | + p.should.have.property('content', 'C2_new'); |
| 92 | + p.should.have.property('approved', true); |
| 93 | + done(); |
| 94 | + }); |
| 95 | + }); |
| 96 | + |
| 97 | + it('should escape number values to defect SQL injection in findById', |
| 98 | + function(done) { |
| 99 | + Post.findById('(SELECT 1+1)', function(err, p) { |
| 100 | + should.exists(err); |
| 101 | + done(); |
| 102 | + }); |
| 103 | + }); |
| 104 | + |
| 105 | + it('should escape number values to defect SQL injection in find', |
| 106 | + function(done) { |
| 107 | + Post.find({where: {id: '(SELECT 1+1)'}}, function(err, p) { |
| 108 | + should.exists(err); |
| 109 | + done(); |
| 110 | + }); |
| 111 | + }); |
| 112 | + |
| 113 | + it('should escape number values to defect SQL injection in find with gt', |
| 114 | + function(done) { |
| 115 | + Post.find({where: {id: {gt: '(SELECT 1+1)'}}}, function(err, p) { |
| 116 | + should.exists(err); |
| 117 | + done(); |
| 118 | + }); |
| 119 | + }); |
| 120 | + |
| 121 | + it('should escape number values to defect SQL injection in find', |
| 122 | + function(done) { |
| 123 | + Post.find({limit: '(SELECT 1+1)'}, function(err, p) { |
| 124 | + should.exists(err); |
| 125 | + done(); |
| 126 | + }); |
| 127 | + }); |
| 128 | + |
| 129 | + it('should escape number values to defect SQL injection in find with inq', |
| 130 | + function(done) { |
| 131 | + Post.find({where: {id: {inq: ['(SELECT 1+1)']}}}, function(err, p) { |
| 132 | + should.exists(err); |
| 133 | + done(); |
| 134 | + }); |
| 135 | + }); |
| 136 | + |
| 137 | +}); |
0 commit comments