Skip to content

Commit cf4e107

Browse files
author
OpenShift Bot
authored
Merge pull request openshift#943 from liggitt/encode-state
Merged by openshift-bot
2 parents 4cd45b9 + e8dbd0b commit cf4e107

File tree

9 files changed

+216
-126
lines changed

9 files changed

+216
-126
lines changed

app/index.html

+2
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ <h1>JavaScript Required</h1>
152152
<script src="bower_components/angular-inview/angular-inview.js"></script>
153153
<script src="bower_components/js-yaml/dist/js-yaml.js"></script>
154154
<script src="bower_components/angular-moment/angular-moment.js"></script>
155+
<script src="bower_components/angular-utf8-base64/angular-utf8-base64.js"></script>
155156
<!-- endbower -->
156157
<!-- endbuild -->
157158

@@ -163,6 +164,7 @@ <h1>JavaScript Required</h1>
163164
<script src="scripts/constants.js"></script>
164165
<script src="scripts/app.js"></script>
165166
<script src="scripts/services/logger.js"></script>
167+
<script src="scripts/services/base64util.js"></script>
166168
<script src="scripts/services/ws.js"></script>
167169
<script src="scripts/services/userstore.js"></script>
168170
<script src="scripts/services/api.js"></script>

app/scripts/app.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ angular
2929
'ui.select',
3030
'key-value-editor',
3131
'angular-inview',
32-
'angularMoment'
32+
'angularMoment',
33+
'ab-base64'
3334
])
3435
.config(function ($routeProvider) {
3536
$routeProvider

app/scripts/services/base64util.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
angular.module('openshiftConsole')
4+
.factory('base64util', function() {
5+
return {
6+
pad: function(data){
7+
if (!data) { return ""; }
8+
switch (data.length % 4) {
9+
case 1: return data + "===";
10+
case 2: return data + "==";
11+
case 3: return data + "=";
12+
default: return data;
13+
}
14+
}
15+
};
16+
});

app/scripts/services/data.js

+2-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* jshint eqeqeq: false, unused: false, expr: true */
33

44
angular.module('openshiftConsole')
5-
.factory('DataService', function($cacheFactory, $http, $ws, $rootScope, $q, API_CFG, APIService, Notification, Logger, $timeout) {
5+
.factory('DataService', function($cacheFactory, $http, $ws, $rootScope, $q, API_CFG, APIService, Notification, Logger, $timeout, base64, base64util) {
66

77
function Data(array) {
88
this._data = {};
@@ -420,14 +420,6 @@ angular.module('openshiftConsole')
420420
return deferred.promise;
421421
};
422422

423-
// https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/btoa
424-
function utf8_to_b64( str ) {
425-
return window.btoa(window.unescape(encodeURIComponent( str )));
426-
}
427-
function b64_to_utf8( str ) {
428-
return decodeURIComponent(window.escape(window.atob( str )));
429-
}
430-
431423
// TODO (bpeterse): Create a new Streamer service & get this out of DataService.
432424
DataService.prototype.createStream = function(resource, name, context, opts, isRaw) {
433425
var self = this;
@@ -461,7 +453,7 @@ DataService.prototype.createStream = function(resource, name, context, opts, isR
461453

462454
var message;
463455
if(!isRaw) {
464-
message = b64_to_utf8(evt.data);
456+
message = base64.decode(base64util.pad(evt.data));
465457
// Count bytes for log streams, which will stop when limitBytes is reached.
466458
// There's no other way to detect we've reach the limit currently.
467459
cumulativeBytes += message.length;

app/scripts/services/login.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ angular.module('openshiftConsole')
2626
return _oauth_redirect_uri;
2727
};
2828

29-
this.$get = function($location, $q, Logger) {
29+
this.$get = function($location, $q, Logger, base64) {
3030
var authLogger = Logger.get("auth");
3131

3232
var getRandomInts = function(length) {
@@ -64,7 +64,7 @@ angular.module('openshiftConsole')
6464
} catch(e) {
6565
authLogger.log("RedirectLoginService.makeState, localStorage error: ", e);
6666
}
67-
return JSON.stringify({then: then, nonce:nonce});
67+
return base64.urlencode(JSON.stringify({then: then, nonce:nonce}));
6868
};
6969
var parseState = function(state) {
7070
var retval = {
@@ -81,7 +81,7 @@ angular.module('openshiftConsole')
8181
}
8282

8383
try {
84-
var data = state ? JSON.parse(state) : {};
84+
var data = state ? JSON.parse(base64.urldecode(state)) : {};
8585
if (data && data.nonce && nonce && data.nonce === nonce) {
8686
retval.verified = true;
8787
retval.then = data.then;

bower.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
"angular-key-value-editor": "2.9.2",
4444
"angular-inview": "1.5.7",
4545
"js-yaml": "3.6.1",
46-
"angular-moment": "1.0.0"
46+
"angular-moment": "1.0.0",
47+
"angular-utf8-base64": "0.0.5"
4748
},
4849
"devDependencies": {
4950
"angular-mocks": "1.3.20",

0 commit comments

Comments
 (0)