Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(validate-token): gracefully handle empty data response #217

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/ng-token-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ angular.module('ng-token-auth', ['ipCookie']).provider('$auth', function() {
$rootScope.$broadcast('auth:validation-error', data);
return _this.rejectDfd({
reason: 'unauthorized',
errors: data.errors
errors: data != null ? data.errors : ['Unspecified error']
});
};
})(this));
Expand Down
2 changes: 1 addition & 1 deletion dist/ng-token-auth.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/ng-token-auth.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ angular.module('ng-token-auth', ['ipCookie'])

@rejectDfd({
reason: 'unauthorized'
errors: data.errors
errors: if data? then data.errors else ['Unspecified error']
})
)
else
Expand Down
18 changes: 18 additions & 0 deletions test/test/unit/ng-token-auth/token-handling.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,21 @@ suite 'token handling', ->
$auth.validateUser()
$timeout.flush()
assert.equal(null, $auth.retrieveData('auth_headers'))

suite 'empty response', ->
setup ->
$auth.getConfig().forceValidateToken = true
$httpBackend
.expectGET('/api/auth/validate_token')
.respond(401, undefined)

dfd = $auth.validateUser()

$httpBackend.flush()

test 'promise should be rejected without error', (done) ->
dfd.catch(->
assert true
done()
)
$timeout.flush()