Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public getMultipartContentType(): string {
return this.multipartContentType;
}
public getSubRequests(): Map {
return this.subRequests;
}
}
class BatchRequestAssemblePolicy extends BaseRequestPolicy {
private batchRequest: InnerBatchRequest;
private readonly dummyResponse: HttpOperationResponse = {
request: new WebResource(),
status: 200,
headers: new HttpHeaders()
};;
constructor(
batchRequest: InnerBatchRequest,
nextPolicy: RequestPolicy,
options: RequestPolicyOptions
) {
super(nextPolicy, options);
this.batchRequest = batchRequest;
}
public async sendRequest(request: WebResource): Promise {
await this.batchRequest.appendSubRequestToBody(request);
return this.dummyResponse; // Intercept request from going to wire
it("Poll: 204", async () => {
const serviceClient: AzureServiceClient = createServiceClient([
{
status: 200,
headers: new HttpHeaders({
"location": "https://fake.azure.com/longRunningOperation2"
})
},
{
status: 204
}
]);
const httpRequest = new WebResource("https://fake.azure.com/longRunningOperation", "PATCH");
await msAssert.throwsAsync(
serviceClient.sendLongRunningRequest(httpRequest),
new Error(`The response with status code 204 from polling for long running operation url "https://fake.azure.com/longRunningOperation2" is not valid.`));
});
});
it("with no AzureServiceClient.longRunningOperationRetryTimeout value and no retry-after header", function () {
const azureServiceClient = new AzureServiceClient(new TokenCredentials("my-fake-token"));
const previousResponse: HttpOperationResponse = {
request: new WebResource(),
status: 200,
headers: new HttpHeaders()
};
assert.strictEqual(getDelayInSeconds(azureServiceClient, previousResponse), 30);
});
sendRequest(httpRequest: WebResource): Promise {
const response: HttpResponse | undefined = responses.shift();
if (!response) {
throw new Error("Not enough responses provided for test.");
}
return Promise.resolve({
request: httpRequest,
status: response.status,
headers: response.headers || new HttpHeaders(),
bodyAsText: typeof response.body === "string" ? response.body : JSON.stringify(response.body),
parsedBody: response.body
});
}
},
sendRequest: async (req: WebResource): Promise => {
if (error === undefined && isMatch(req, expectedRequestHeaders)) {
const httpResponse: HttpOperationResponse = {
request: req,
status: 200,
headers: new HttpHeaders(),
bodyAsText: JSON.stringify(response)
};
return Promise.resolve(httpResponse);
} else {
return Promise.reject(error);
}
}
};
sendRequest: async (request: WebResource): Promise => {
if (error === undefined) {
const httpResponse: HttpOperationResponse = {
request: request,
status: 200,
headers: new HttpHeaders(),
bodyAsText: JSON.stringify(response)
};
return Promise.resolve(httpResponse);
} else {
return Promise.reject(error);
}
}
};
protected signRequest(request: WebResource): WebResource {
if (!request.headers) {
request.headers = new HttpHeaders();
}
request.headers.set(
HeaderConstants.AUTHORIZATION,
`${this.authorizationScheme} ${this.tokenCredential.token}`
);
return request;
}
}
protected signRequest(request: WebResource): WebResource {
if (!request.headers) {
request.headers = new HttpHeaders();
}
request.headers.set(
HeaderConstants.AUTHORIZATION,
`${this.authorizationScheme} ${this.tokenCredential.token}`
);
return request;
}
}