Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async forwardToSkill(
turnContext: TurnContext,
activity: Partial,
tokenRequestHandler?: TokenRequestHandler
): Promise {
// Serialize the activity and POST to the Skill endpoint
const requestOptions: RequestPrepareOptions = {
method: 'POST',
url: this.skillManifest.endpoint,
body: activity
};
const request: WebResource = new WebResource().prepare(requestOptions);
MicrosoftAppCredentials.trustServiceUrl(this.skillManifest.endpoint);
await this.appCredentials.signRequest(request);
const response: HttpOperationResponse = await this.httpClient.sendRequest(request);
if (response.status < 200 || response.status >= 300) {
const result: string = `HTTP error when forwarding activity to the skill: Status Code:${
response.status
}, Message: '${
response.bodyAsText
}'`;
await turnContext.sendActivity({
type: ActivityTypes.Trace,
text: result
it("Headers: Azure-AsyncOperation", async () => {
const serviceClient: AzureServiceClient = createServiceClient([
{
status: 202,
headers: new HttpHeaders({
"azure-asyncoperation": "https://fake.azure.com/longRunningOperation2"
})
},
{
status: 200,
body: {
status: "Succeeded"
}
}
]);
const httpRequest = new WebResource("https://fake.azure.com/longRunningOperation", "DELETE");
const httpResponse: HttpOperationResponse = await serviceClient.sendLongRunningRequest(httpRequest);
assert.strictEqual(httpResponse.status, 200);
assert.strictEqual(httpResponse.bodyAsText, `{"status":"Succeeded"}`);
assert.deepEqual(httpResponse.parsedBody, { status: "Succeeded" });
assert.strictEqual(httpResponse.request.url, "https://fake.azure.com/longRunningOperation2");
});
it("with 11 AzureServiceClient.longRunningOperationRetryTimeout and 12 retry-after header", function () {
const azureServiceClient = new AzureServiceClient(new TokenCredentials("my-fake-token"), { longRunningOperationRetryTimeout: 11 });
const previousResponse: HttpOperationResponse = {
request: new WebResource(),
status: 200,
headers: new HttpHeaders({ "retry-after": "12" })
};
assert.strictEqual(getDelayInSeconds(azureServiceClient, previousResponse), 11);
});
});
})
},
{
status: 200,
body: {
status: "Succeeded"
}
},
{
status: 200,
body: {
a: "A"
}
}
]);
const httpRequest = new WebResource("https://fake.azure.com/longRunningOperation", "PATCH");
const httpResponse: HttpOperationResponse = await serviceClient.sendLongRunningRequest(httpRequest);
assert.strictEqual(httpResponse.status, 200);
assert.strictEqual(httpResponse.bodyAsText, `{"a":"A"}`);
assert.deepEqual(httpResponse.parsedBody, { a: "A" });
assert.strictEqual(httpResponse.request.url, "https://fake.azure.com/longRunningOperation");
});
})
},
{
status: 200,
body: {
status: "Succeeded"
}
},
{
status: 200,
body: {
a: "A"
}
}
]);
const httpRequest = new WebResource("https://fake.azure.com/longRunningOperation", "POST");
const httpResponse: HttpOperationResponse = await serviceClient.sendLongRunningRequest(httpRequest);
assert.strictEqual(httpResponse.status, 200);
assert.strictEqual(httpResponse.bodyAsText, `{"a":"A"}`);
assert.deepEqual(httpResponse.parsedBody, { a: "A" });
assert.strictEqual(httpResponse.request.url, "https://fake.azure.com/longRunningOperation3");
});
it ("adds custom user agent if specified", async () => {
const client = new AzureServiceClient(new TokenCredentials("fake-token"), { userAgent: "custom-ua" });
const request = new WebResource("https://microsoft.com");
await client.sendRequest(request);
const telemetry = request.headers.get("user-agent")!;
assert.equal(telemetry, "custom-ua");
});
status: 200,
headers: new HttpHeaders({
"location": "https://fake.azure.com/longRunningOperation2"
})
},
{
status: 202
},
{
status: 200,
body: {
a: "A"
}
}
]);
const httpRequest = new WebResource("https://fake.azure.com/longRunningOperation", "PUT");
const httpResponse: HttpOperationResponse = await serviceClient.sendLongRunningRequest(httpRequest);
assert.strictEqual(httpResponse.status, 200);
assert.strictEqual(httpResponse.bodyAsText, `{"a":"A"}`);
assert.deepEqual(httpResponse.parsedBody, { a: "A" });
assert.strictEqual(httpResponse.request.url, "https://fake.azure.com/longRunningOperation2");
});
protected prepareRequestOptions(): WebResource {
const endpoint = this.msiEndpoint.endsWith("/") ? this.msiEndpoint : `${this.msiEndpoint}/`;
const resource = encodeURIComponent(this.resource);
const getUrl = `${endpoint}?resource=${resource}&api-version=${this.msiApiVersion}`;
const reqOptions: RequestPrepareOptions = {
url: getUrl,
headers: {
"secret": this.msiSecret
},
method: "GET"
};
const webResource = new WebResource();
return webResource.prepare(reqOptions);
}
}
return `${this.body}${this.batchRequestEnding}${HTTP_LINE_ENDING}`;
}
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);