Skip to content

Commit

Permalink
- fix silkimen#198: Cookie header is always passed even if there is n…
Browse files Browse the repository at this point in the history
…o cookie

- some cleanup
  • Loading branch information
Sefa Ilkimen committed Apr 9, 2019
1 parent 13976bb commit d444363
Show file tree
Hide file tree
Showing 23 changed files with 65 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
node_modules/**
test/app-template/www/certificates/*.cer
test/e2e-app-template/www/certificates/*.cer
tags
.zedstate
npm-debug.log
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 2.0.8

- Fixed #198: cookie header is always passed even if there is no cookie
- Fixed #201: browser implementation is broken due to broken dependency
- Fixed #197: iOS crashes when multiple request are done simultaneously (reverted a8e3637)
- Fixed #189: error code mappings are not precise
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"testandroid": "npm run updatecert && ./scripts/build-test-app.sh --android --emulator && ./scripts/test-app.sh --android --emulator",
"testios": "npm run updatecert && ./scripts/build-test-app.sh --ios --emulator && ./scripts/test-app.sh --ios --emulator",
"testapp": "npm run testandroid && npm run testios",
"testjs": "mocha ./test/js-mocha-specs.js",
"testjs": "mocha ./test/js-specs.js",
"test": "npm run testjs && npm run testapp",
"release": "npm run test && ./scripts/release.sh"
},
Expand Down
5 changes: 3 additions & 2 deletions scripts/build-test-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ while :; do
shift
done

printf 'Building test app for %s\n' $PLATFORM
rm -rf $ROOT/temp
mkdir $ROOT/temp
cp -r $ROOT/test/app-template/. $ROOT/temp/
cp $ROOT/test/app-test-definitions.js $ROOT/temp/www/
cp -r $ROOT/test/e2e-app-template/. $ROOT/temp/
cp $ROOT/test/e2e-specs.js $ROOT/temp/www/
rsync -ax --exclude node_modules --exclude scripts --exclude temp --exclude test $ROOT/. $WORKINGCOPY
cd $ROOT/temp
$CDV prepare
Expand Down
19 changes: 0 additions & 19 deletions scripts/setup-android-sdk.sh

This file was deleted.

3 changes: 2 additions & 1 deletion scripts/test-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ if [ $CI == "true" ] && ([ -z $SAUCE_USERNAME ] || [ -z $SAUCE_ACCESS_KEY ]); th
exit 0;
fi

printf 'Running e2e tests\n'
pushd $ROOT
./node_modules/.bin/mocha ./test/app-mocha-specs/test.js "$@"
./node_modules/.bin/mocha ./test/e2e-tooling/test.js "$@"
popd
2 changes: 1 addition & 1 deletion scripts/update-test-cert.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const https = require('https');
const path = require('path');

const SOURCE_HOST = 'httpbin.org';
const TARGET_PATH = path.join(__dirname, '../test/app-template/www/certificates/httpbin.org.cer');
const TARGET_PATH = path.join(__dirname, '../test/e2e-app-template/www/certificates/httpbin.org.cer');

const getCert = hostname => new Promise((resolve, reject) => {
const options = {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h1 id="descriptionLbl">Advanced HTTP test suite</h1>
<button id="nextBtn">Run next test</button>

<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="app-test-definitions.js"></script>
<script type="text/javascript" src="e2e-specs.js"></script>
<script type="text/javascript" src="index.js"></script>
</body>
</html>
File renamed without changes.
3 changes: 1 addition & 2 deletions test/app-test-definitions.js → test/e2e-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,7 @@ const tests = [
JSON
.parse(result.data.data)
.headers
.Cookie
.should.be.equal('');
.should.not.have.property('Cookie');
}
},
{
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/app-mocha-specs/test.js → test/e2e-tooling/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const wd = require('wd');
const apps = require('./helpers/apps');
const caps = Object.assign({}, require('./helpers/caps'));
const serverConfig = require('./helpers/server');
const testDefinitions = require('../app-test-definitions');
const testDefinitions = require('../e2e-specs');
const pkgjson = require('../../package.json');

describe('Advanced HTTP', function() {
Expand Down
27 changes: 27 additions & 0 deletions test/js-mocha-specs.js → test/js-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,30 @@ describe('URL util', function () {
.should.equal('http://ilkimen.net/?myParam=myValue&param1=value1#myHash');
});
});

describe('Common helpers', function () {
describe('mergeHeaders(globalHeaders, localHeaders)', function () {
const init = require('../www/helpers');
init.debug = true;

const helpers = init(null, null, null);

it('merges empty header sets correctly', () => {
helpers.mergeHeaders({}, {}).should.eql({});
});
});

describe('getCookieHeader(url)', function () {
it('resolves cookie header correctly when no cookie is set #198', () => {
const helpers = require('../www/helpers')(null, { getCookieString: () => '' }, null);

helpers.getCookieHeader('http://ilkimen.net').should.eql({});
});

it('resolves cookie header correctly when a cookie is set', () => {
const helpers = require('../www/helpers')(null, { getCookieString: () => 'cookie=value' }, null);

helpers.getCookieHeader('http://ilkimen.net').should.eql({ Cookie: 'cookie=value' });
});
});
})
28 changes: 26 additions & 2 deletions www/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = function init(jsUtil, cookieHandler, messages) {
var validClientAuthModes = ['none', 'systemstore', 'file'];
var validHttpMethods = ['get', 'put', 'post', 'patch', 'head', 'delete', 'upload', 'download'];

return {
var interface = {
b64EncodeUnicode: b64EncodeUnicode,
checkSerializer: checkSerializer,
checkSSLCertMode: checkSSLCertMode,
Expand All @@ -19,6 +19,24 @@ module.exports = function init(jsUtil, cookieHandler, messages) {
handleMissingOptions: handleMissingOptions
};

// expose all functions for testing purposes
if (init.debug) {
interface.mergeHeaders = mergeHeaders;
interface.checkForValidStringValue = checkForValidStringValue;
interface.checkKeyValuePairObject = checkKeyValuePairObject;
interface.checkHttpMethod = checkHttpMethod;
interface.checkTimeoutValue = checkTimeoutValue;
interface.checkHeadersObject = checkHeadersObject;
interface.checkParamsObject = checkParamsObject;
interface.resolveCookieString = resolveCookieString;
interface.createFileEntry = createFileEntry;
interface.getCookieHeader = getCookieHeader;
interface.getMatchingHostHeaders = getMatchingHostHeaders;
interface.getAllowedDataTypes = getAllowedDataTypes;
}

return interface;

// Thanks Mozilla: https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_.22Unicode_Problem.22
function b64EncodeUnicode(str) {
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) {
Expand Down Expand Up @@ -158,7 +176,13 @@ module.exports = function init(jsUtil, cookieHandler, messages) {
}

function getCookieHeader(url) {
return { Cookie: cookieHandler.getCookieString(url) };
var cookieString = cookieHandler.getCookieString(url);

if (cookieString.length) {
return { Cookie: cookieHandler.getCookieString(url) };
}

return {};
}

function getMatchingHostHeaders(url, headersList) {
Expand Down

0 comments on commit d444363

Please sign in to comment.