|
724 | 724 | $httpBackend.flush();
|
725 | 725 | });
|
726 | 726 |
|
| 727 | + it('should parse the response of a single batch request which contains the Angular "JSON Vulnerability Protection" prefix and multiple responses', function (done) { |
| 728 | + var batchConfig = { |
| 729 | + batchEndpointUrl: 'http://www.someservice.com/batch', |
| 730 | + batchRequestCollectionDelay: 200, |
| 731 | + minimumBatchSize: 1, |
| 732 | + adapter: defaultBatchAdapter |
| 733 | + }, |
| 734 | + postData = '--31fcc127-a593-4e1d-86f3-57e45375848f\r\nContent-Type: application/http; msgtype=request\r\n\r\nGET /resource HTTP/1.1\r\nHost: www.gogle.com\r\n\r\n\r\n--31fcc127-a593-4e1d-86f3-57e45375848f' + |
| 735 | + '\r\nContent-Type: application/http; msgtype=request\r\n\r\nGET /resource-two HTTP/1.1\r\nHost: www.gogle.com\r\n\r\n\r\n--31fcc127-a593-4e1d-86f3-57e45375848f--', |
| 736 | + responseData = '--31fcc127-a593-4e1d-86f3-57e45375848f\r\nContent-Type: application/http; msgtype=response\r\n\r\n' + |
| 737 | + 'HTTP/1.1 200 OK\r\nContent-Type: application/json; charset=utf-8;\r\n\r\n' + |
| 738 | + ')]}\',\n' + // JSON Vulnerability Protection prefix (see https://docs.angularjs.org/api/ng/service/$http#json-vulnerability-protection ) |
| 739 | + '{"results":[{"BusinessDescription":"Some text here"}],"inlineCount":35}' + |
| 740 | + '\r\n--31fcc127-a593-4e1d-86f3-57e45375848f\r\n' + |
| 741 | + '\r\nContent-Type: application/http; msgtype=response\r\n\r\n' + |
| 742 | + 'HTTP/1.1 200 OK\r\nContent-Type: application/json; charset=utf-8;\r\n\r\n' + |
| 743 | + ')]}\',\n' + // JSON Vulnerability Protection prefix (see https://docs.angularjs.org/api/ng/service/$http#json-vulnerability-protection ) |
| 744 | + '[{"name":"Jon","id":1,"age":30},{"name":"Laurie","id":2,"age":29}]' + |
| 745 | + '\r\n--31fcc127-a593-4e1d-86f3-57e45375848f--\r\n', |
| 746 | + |
| 747 | + completedFnInvocationCount = 0, |
| 748 | + |
| 749 | + completedFn = function () { |
| 750 | + completedFnInvocationCount += 1; |
| 751 | + if (completedFnInvocationCount === 2) { |
| 752 | + done(); |
| 753 | + } |
| 754 | + }; |
| 755 | + |
| 756 | + $httpBackend.expectPOST(batchConfig.batchEndpointUrl, postData).respond(200, responseData, { |
| 757 | + 'content-type': 'multipart/mixed; boundary="31fcc127-a593-4e1d-86f3-57e45375848f"' |
| 758 | + }, 'OK'); |
| 759 | + |
| 760 | + sandbox.stub(httpBatchConfig, 'calculateBoundary').returns('31fcc127-a593-4e1d-86f3-57e45375848f'); |
| 761 | + sandbox.stub(httpBatchConfig, 'getBatchConfig').returns(batchConfig); |
| 762 | + |
| 763 | + httpBatcher.batchRequest({ |
| 764 | + url: 'http://www.gogle.com/resource', |
| 765 | + method: 'GET', |
| 766 | + callback: function (statusCode, data) { |
| 767 | + expect(data).to.deep.equal({ |
| 768 | + results: [{ |
| 769 | + BusinessDescription: 'Some text here' |
| 770 | + }], |
| 771 | + inlineCount: 35 |
| 772 | + }); |
| 773 | + completedFn(); |
| 774 | + } |
| 775 | + }); |
| 776 | + |
| 777 | + httpBatcher.batchRequest({ |
| 778 | + url: 'http://www.gogle.com/resource-two', |
| 779 | + method: 'GET', |
| 780 | + callback: function (statusCode, data) { |
| 781 | + expect(data).to.deep.equal([{ |
| 782 | + name: 'Jon', |
| 783 | + id: 1, |
| 784 | + age: 30 |
| 785 | + }, { |
| 786 | + name: 'Laurie', |
| 787 | + id: 2, |
| 788 | + age: 29 |
| 789 | + }]); |
| 790 | + completedFn(); |
| 791 | + } |
| 792 | + }); |
| 793 | + |
| 794 | + $timeout.flush(); |
| 795 | + $httpBackend.flush(); |
| 796 | + }); |
| 797 | + |
727 | 798 | it('should return original data for non strings when trim Angular "JSON Vulnerability Protection" prefix', function (done) {
|
728 | 799 | var responseData = [{
|
729 | 800 | "headers": {
|
|
0 commit comments