Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. var express = require('express');
  2. var bodyParser = require('body-parser');
  3. var soap = require('soap');
  4. var LOGIN_URL = '...';
  5.  
  6. var app = express();
  7. app.use(bodyParser.json());
  8.  
  9. app.get('/', function (req, res) {
  10. res.send('Hello World!');
  11. });
  12.  
  13. app.post('/api/authenticate/', function (req, res) {
  14. console.log(req, res);
  15. var auth = "Basic " + new Buffer(req.body.username + ":" + req.body.password).toString("base64");
  16. console.log(auth);
  17. soap.createClient(LOGIN_URL, { wsdl_headers: {Authorization: auth} }, function(err, client) {
  18. console.log(err);
  19. if (err === null) {
  20. res.sendStatus(200);
  21. }
  22. else {
  23. res.sendStatus(401);
  24. }
  25. });
  26. });
  27.  
  28. app.listen(3000, function () {
  29. console.log("Listening on port 3000!");
  30. });
  31.  
  32.  
  33. // inline testing
  34. // attempt with correct credentials
  35. var req = {};
  36. req.body = {};
  37. req.body.username = "correctUsername";
  38. req.body.password = "correctPassword";
  39.  
  40. var auth = "Basic " + new Buffer(req.body.username + ":" + req.body.password).toString("base64");
  41. console.log(auth);
  42. soap.createClient(LOGIN_URL, { wsdl_headers: {Authorization: auth} }, function(err, client) {
  43. console.log(err);
  44. if (err === null) {
  45. console.log("ok1");
  46. }
  47. else {
  48. console.log("not ok1");
  49. }
  50. });
  51. // => "ok1"
  52.  
  53. // attempt with incorrect credentials
  54. req.body.username = "incorrectUsername";
  55.  
  56. var auth = "Basic " + new Buffer(req.body.username + ":" + req.body.password).toString("base64");
  57. console.log(auth);
  58. soap.createClient(LOGIN_URL, { wsdl_headers: {Authorization: auth} }, function(err, client) {
  59. console.log(err);
  60. if (err === null) {
  61. console.log("ok2");
  62. }
  63. else {
  64. console.log("not ok2");
  65. }
  66. });
  67. // => "not ok2"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement