|
1 |
| -var expect = require('chai').expect, |
| 1 | +var _ = require('lodash'), |
| 2 | + expect = require('chai').expect, |
2 | 3 | { Request } = require('postman-collection/lib/collection/request'),
|
3 | 4 | { Url } = require('postman-collection/lib/collection/url'),
|
4 | 5 | convert = require('../../index').convert,
|
@@ -1026,5 +1027,122 @@ describe('curl convert function', function () {
|
1026 | 1027 | });
|
1027 | 1028 | });
|
1028 | 1029 | });
|
| 1030 | + |
| 1031 | + describe('should correctly handle NTLM auth', function () { |
| 1032 | + const sampleRequest = { |
| 1033 | + 'method': 'POST', |
| 1034 | + 'header': [], |
| 1035 | + 'auth': { |
| 1036 | + 'type': 'ntlm', |
| 1037 | + 'ntlm': [] |
| 1038 | + }, |
| 1039 | + 'url': { |
| 1040 | + 'raw': 'https://postman-echo.com/post', |
| 1041 | + 'protocol': 'https', |
| 1042 | + 'host': [ |
| 1043 | + 'postman-echo', |
| 1044 | + 'com' |
| 1045 | + ], |
| 1046 | + 'path': [ |
| 1047 | + 'post' |
| 1048 | + ] |
| 1049 | + } |
| 1050 | + }; |
| 1051 | + |
| 1052 | + it('when no username or password is present', function () { |
| 1053 | + const request = new Request(sampleRequest); |
| 1054 | + |
| 1055 | + convert(request, {}, function (error, snippet) { |
| 1056 | + if (error) { |
| 1057 | + expect.fail(null, null, error); |
| 1058 | + } |
| 1059 | + expect(snippet).to.be.a('string'); |
| 1060 | + expect(snippet).to.not.include('--ntlm'); |
| 1061 | + }); |
| 1062 | + }); |
| 1063 | + |
| 1064 | + it('when empty username and password is present', function () { |
| 1065 | + const request = new Request(Object.assign({ auth: { |
| 1066 | + 'type': 'ntlm', |
| 1067 | + 'ntlm': [ |
| 1068 | + {key: 'username', value: ''}, |
| 1069 | + {key: 'password', value: ''} |
| 1070 | + ] |
| 1071 | + }}, sampleRequest)); |
| 1072 | + |
| 1073 | + convert(request, {}, function (error, snippet) { |
| 1074 | + if (error) { |
| 1075 | + expect.fail(null, null, error); |
| 1076 | + } |
| 1077 | + expect(snippet).to.be.a('string'); |
| 1078 | + expect(snippet).to.not.include('--ntlm'); |
| 1079 | + }); |
| 1080 | + }); |
| 1081 | + |
| 1082 | + it('when correct username and password is present with single quotes as option', function () { |
| 1083 | + const request = new Request(_.set(sampleRequest, 'auth.ntlm', [ |
| 1084 | + {key: 'username', value: 'joh\'n'}, |
| 1085 | + {key: 'password', value: 'tennesse"e'} |
| 1086 | + ])); |
| 1087 | + |
| 1088 | + convert(request, { quoteType: 'single' }, function (error, snippet) { |
| 1089 | + if (error) { |
| 1090 | + expect.fail(null, null, error); |
| 1091 | + } |
| 1092 | + expect(snippet).to.be.a('string'); |
| 1093 | + expect(snippet).to.equal('curl --ntlm --user \'joh\'\\\'\'n:tennesse"e\' --location' + |
| 1094 | + ' --request POST \'https://postman-echo.com/post\''); |
| 1095 | + }); |
| 1096 | + }); |
| 1097 | + |
| 1098 | + it('when correct username and password is present with double as option', function () { |
| 1099 | + const request = new Request(_.set(sampleRequest, 'auth.ntlm', [ |
| 1100 | + {key: 'username', value: 'joh\'n'}, |
| 1101 | + {key: 'password', value: 'tennesse"e'} |
| 1102 | + ])); |
| 1103 | + |
| 1104 | + convert(request, { quoteType: 'double' }, function (error, snippet) { |
| 1105 | + if (error) { |
| 1106 | + expect.fail(null, null, error); |
| 1107 | + } |
| 1108 | + expect(snippet).to.be.a('string'); |
| 1109 | + expect(snippet).to.equal('curl --ntlm --user "joh\'n:tennesse\\"e" --location' + |
| 1110 | + ' --request POST "https://postman-echo.com/post"'); |
| 1111 | + }); |
| 1112 | + }); |
| 1113 | + |
| 1114 | + it('when correct username and password is present with long format option disabled', function () { |
| 1115 | + const request = new Request(_.set(sampleRequest, 'auth.ntlm', [ |
| 1116 | + {key: 'username', value: 'joh\'n'}, |
| 1117 | + {key: 'password', value: 'tennesse"e'} |
| 1118 | + ])); |
| 1119 | + |
| 1120 | + convert(request, { longFormat: false }, function (error, snippet) { |
| 1121 | + if (error) { |
| 1122 | + expect.fail(null, null, error); |
| 1123 | + } |
| 1124 | + expect(snippet).to.be.a('string'); |
| 1125 | + expect(snippet).to.equal('curl --ntlm -u \'joh\'\\\'\'n:tennesse"e\' -L' + |
| 1126 | + ' -X POST \'https://postman-echo.com/post\''); |
| 1127 | + }); |
| 1128 | + }); |
| 1129 | + |
| 1130 | + it('when username and password is present with domain as well', function () { |
| 1131 | + const request = new Request(_.set(sampleRequest, 'auth.ntlm', [ |
| 1132 | + {key: 'username', value: 'joh\'n'}, |
| 1133 | + {key: 'password', value: 'tennesse"e'}, |
| 1134 | + {key: 'domain', value: 'radio'} |
| 1135 | + ])); |
| 1136 | + |
| 1137 | + convert(request, {}, function (error, snippet) { |
| 1138 | + if (error) { |
| 1139 | + expect.fail(null, null, error); |
| 1140 | + } |
| 1141 | + expect(snippet).to.be.a('string'); |
| 1142 | + expect(snippet).to.equal('curl --ntlm --user \'radio\\joh\'\\\'\'n:tennesse"e\' --location' + |
| 1143 | + ' --request POST \'https://postman-echo.com/post\''); |
| 1144 | + }); |
| 1145 | + }); |
| 1146 | + }); |
1029 | 1147 | });
|
1030 | 1148 | });
|
0 commit comments