Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.
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 src/armTemplates/resources/appInsights.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ArmResourceTemplateGenerator, ArmResourceTemplate } from "../../models/armTemplates";
import { ServerlessAzureConfig, ResourceConfig } from "../../models/serverless";
import { ServerlessAzureConfig } from "../../models/serverless";

export class AppInsightsResource implements ArmResourceTemplateGenerator {
public static getResourceName(config: ServerlessAzureConfig) {
Expand Down
2 changes: 1 addition & 1 deletion src/armTemplates/resources/hostingEnvironment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ArmResourceTemplateGenerator, ArmResourceTemplate } from "../../models/armTemplates";
import { ServerlessAzureConfig, ResourceConfig } from "../../models/serverless";
import { ServerlessAzureConfig } from "../../models/serverless";

export class HostingEnvironmentResource implements ArmResourceTemplateGenerator {
public static getResourceName(config: ServerlessAzureConfig) {
Expand Down
2 changes: 1 addition & 1 deletion src/armTemplates/resources/virtualNetwork.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ArmResourceTemplateGenerator, ArmResourceTemplate } from "../../models/armTemplates";
import { ServerlessAzureConfig, ResourceConfig } from "../../models/serverless";
import { ServerlessAzureConfig } from "../../models/serverless";

export class VirtualNetworkResource implements ArmResourceTemplateGenerator {
public static getResourceName(config: ServerlessAzureConfig) {
Expand Down
38 changes: 31 additions & 7 deletions src/services/functionAppService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { ArmDeployment, ArmTemplateType } from "../models/armTemplates";
jest.mock("@azure/arm-resources")

describe("Function App Service", () => {

const app = MockFactory.createTestSite();
const slsService = MockFactory.createTestService();
const variables = MockFactory.createTestVariables();
Expand All @@ -31,12 +30,8 @@ describe("Function App Service", () => {
const authKeyUrl = `${baseUrl}${app.id}/functions/admin/token?api-version=2016-08-01`;
const syncTriggersUrl = `${baseUrl}${app.id}/syncfunctiontriggers?api-version=2016-08-01`;
const listFunctionsUrl = `${baseUrl}${app.id}/functions?api-version=2016-08-01`;
const scmDomain = app.enabledHostNames.find((hostname) => hostname.endsWith("scm.azurewebsites.net"));
const uploadUrl = `https://${scmDomain}/api/zipdeploy/`;

beforeAll(() => {

// TODO: How to spy on default exported function?
const axiosMock = new MockAdapter(axios);

// Master Key
Expand All @@ -59,7 +54,6 @@ describe("Function App Service", () => {
});

beforeEach(() => {

WebSiteManagementClient.prototype.webApps = {
get: jest.fn(() => app),
deleteFunction: jest.fn(),
Expand Down Expand Up @@ -197,11 +191,41 @@ describe("Function App Service", () => {
});

it("uploads functions", async () => {
const scmDomain = app.enabledHostNames.find((hostname) => hostname.endsWith("scm.azurewebsites.net"));
const expectedUploadUrl = `https://${scmDomain}/api/zipdeploy/`;

const service = createService();
await service.uploadFunctions(app);

expect((FunctionAppService.prototype as any).sendFile).toBeCalledWith({
method: "POST",
uri: expectedUploadUrl,
json: true,
headers: {
Authorization: `Bearer ${variables["azureCredentials"].tokenCache._entries[0].accessToken}`,
Accept: "*/*",
ContentType: "application/octet-stream",
}
}, slsService["artifact"])
});

it("uploads functions with custom SCM domain (aka App service environments)", async () => {
const customApp = {
...MockFactory.createTestSite("CustomAppWithinASE"),
enabledHostNames: [
"myapi.customase.p.azurewebsites.net",
"myapi.scm.customase.p.azurewebsites.net"
],
}

const expectedUploadUrl = `https://${customApp.enabledHostNames[1]}/api/zipdeploy/`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does Azure provide some API where we can check for this? What if they change the scm domain url?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh. fair enough.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we include this as a comment so future developers know where this came from?


const service = createService();
await service.uploadFunctions(customApp);

expect((FunctionAppService.prototype as any).sendFile).toBeCalledWith({
method: "POST",
uri: uploadUrl,
uri: expectedUploadUrl,
json: true,
headers: {
Authorization: `Bearer ${variables["azureCredentials"].tokenCache._entries[0].accessToken}`,
Expand Down
2 changes: 1 addition & 1 deletion src/services/functionAppService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export class FunctionAppService extends BaseService {
*/
private getScmDomain(functionApp: Site) {
return functionApp.enabledHostNames.find((hostName: string) => {
return hostName.endsWith("scm.azurewebsites.net");
return hostName.includes(".scm.") && hostName.endsWith(".azurewebsites.net");
});
}
}