Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
calidion committed Nov 14, 2015
1 parent 8251912 commit ffc0de3
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 4 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module.exports = {
cb(false, json.xml);
} catch (e) {
console.log(e);
throw e;
cb(true, e);
}
} else {
cb(true, {message: body});
Expand Down Expand Up @@ -98,7 +98,7 @@ module.exports = {
cb(false, json.xml);
} catch (e) {
console.log(e);
throw e;
cb(true, e);
}
} else {
cb(true, {message: body});
Expand Down
Empty file added test/cert/a.p12
Empty file.
81 changes: 79 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,23 @@ describe('node-weixin-request node module', function () {
});
});

it("should be able to post ssl data", function(done) {
it('should not be able to request with xml data incorrectly', function (done) {
var nock = require('nock');
var url = 'http://domain.com';
var fs = require('fs');
var path = require('path');
var xml = fs.readFileSync(path.resolve(__dirname, './sample.xml'));

nock(url)
.get('/')
.reply(200, 'safdsfsfd');
nodeWeixinRequest.xml(url, xml, function (error) {
assert.equal(true, error);
done();
});
});

it("should be able to post ssl data", function (done) {
var nock = require('nock');
var url = 'https://domain.com';
var ssl = {
Expand All @@ -150,7 +166,7 @@ describe('node-weixin-request node module', function () {
});
});

it("should be able to post ssl data", function(done) {
it("should be able to post ssl data", function (done) {
var nock = require('nock');
var url = 'https://domain.com';
var ssl = {
Expand All @@ -168,4 +184,65 @@ describe('node-weixin-request node module', function () {
done();
});
});

it("should be able to post ssl data", function (done) {
var nock = require('nock');
var url = 'https://domain.com';
var path = require('path');
var file = path.resolve(__dirname, './cert/a.p12');
var ssl = {
pkcs12: file,
pfxKey: 'sodosodf'
};
var reply = "<xml><data>aodsosfd</data></xml>";

nock(url)
.post('/')
.reply(200, reply);
nodeWeixinRequest.xmlssl(url, '<xml></xml>', ssl, function (error, json) {
assert.equal(true, error === false);
assert.equal(true, json.data === 'aodsosfd');
done();
});
});

it("should not be able to post ssl data", function (done) {
var nock = require('nock');
var url = 'https://domain.com';
var path = require('path');
var file = path.resolve(__dirname, './cert/a.p12');
var ssl = {
pkcs12: file,
pfxKey: 'sodosodf'
};

nock(url)
.post('/')
.reply(200, 'sfdsfdf');
nodeWeixinRequest.xmlssl(url, '<xml></xml>', ssl, function (error, exception) {
assert.equal(true, error);
assert.equal(true, exception instanceof Error);
done();
});
});

it("should be able to post ssl data", function (done) {
var nock = require('nock');
var url = 'https://domain.com';
var path = require('path');
var file = path.resolve(__dirname, './cert/a.p12');
var ssl = {
pkcs12: file,
pfxKey: 'sodosodf'
};

nock(url)
.post('/')
.reply(500, 'sdfosffd');
nodeWeixinRequest.xmlssl(url, '<xml></xml>', ssl, function (error, json) {
assert.equal(true, error);
assert.equal(true, json.message === 'sdfosffd');
done();
});
});
});

0 comments on commit ffc0de3

Please sign in to comment.