Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
SQUASH ME: feat($httpBackend): JSONP requests now require trusted res…
Browse files Browse the repository at this point in the history
…ource
  • Loading branch information
petebacondarwin committed Sep 20, 2016
1 parent da74d2d commit 3d1512b
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions test/ng/httpSpec.js
Expand Up @@ -1044,27 +1044,25 @@ describe('$http', function() {
describe('jsonp trust', function() {
it('should throw error if the url is not a trusted resource', function() {
var success, error;
$http({method: 'JSONP', url: 'http://example.org/path?cb=JSON_CALLBACK', callback: callback}).catch(
$http({method: 'JSONP', url: 'http://example.org/path?cb=JSON_CALLBACK'}).catch(
function(e) { error = e; }
);
$rootScope.$digest();
expect(error.message).toContain('[$sce:insecurl]');
});

it('should not throw error if the url is an explicitly trusted resource', function() {
expect(function() {
$httpBackend.expect('JSONP', 'http://example.org/path?cb=JSON_CALLBACK').respond('');
$http({ method: 'JSONP', url: $sce.trustAsResourceUrl('http://example.org/path?cb=JSON_CALLBACK'), callback: callback});
}).not.toThrow();
it('should accept an explicitly trusted resource url', function() {
$httpBackend.expect('JSONP', 'http://example.org/path?cb=JSON_CALLBACK').respond('');
$http({ method: 'JSONP', url: $sce.trustAsResourceUrl('http://example.org/path?cb=JSON_CALLBACK')});
});

it('jsonp() should accept explictly trusted urls', inject(['$sce', function($sce) {
it('jsonp() should accept explictly trusted urls', function() {
$httpBackend.expect('JSONP', '/url').respond('');
$http({method: 'JSONP', url: $sce.trustAsResourceUrl('/url')});

$httpBackend.expect('JSONP', '/url?a=b').respond('');
$http({method: 'JSONP', url: $sce.trustAsResourceUrl('/url'), params: {a: 'b'}});
}]));
});
});

describe('callbacks', function() {
Expand Down

0 comments on commit 3d1512b

Please sign in to comment.