Skip to content

Commit

Permalink
fix: remove spec auth support for VS
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethBWSong committed Sep 24, 2024
1 parent 6e5f4d8 commit 0715b5f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/fx-core/src/component/generator/apiSpec/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ const enum telemetryEvents {
failedToGetGenerateWarning = "failed-to-get-generate-warning",
}

export function getParserOptions(type: ProjectType, isDeclarativeCopilot?: boolean): ParseOptions {
export function getParserOptions(
type: ProjectType,
isDeclarativeCopilot?: boolean,
platform?: string
): ParseOptions {
return type === ProjectType.Copilot
? {
isGptPlugin: isDeclarativeCopilot,
Expand Down Expand Up @@ -113,7 +117,7 @@ export function getParserOptions(type: ProjectType, isDeclarativeCopilot?: boole
}
: {
projectType: type,
allowBearerTokenAuth: true, // Currently, API key auth support is actually bearer token auth
allowBearerTokenAuth: !!platform && platform === Platform.VS ? false : true, // Currently, API key auth support is actually bearer token auth
allowMultipleParameters: true,
allowOauth2: featureFlagManager.getBooleanValue(FeatureFlags.SMEOAuth),
};
Expand Down Expand Up @@ -158,7 +162,10 @@ export async function listOperations(
: ProjectType.SME;

try {
const specParser = new SpecParser(apiSpecUrl as string, getParserOptions(projectType));
const specParser = new SpecParser(
apiSpecUrl as string,
getParserOptions(projectType, undefined, inputs.platform)
);
const validationRes = await specParser.validate();
validationRes.errors = formatValidationErrors(validationRes.errors, inputs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,36 @@ describe("listOperations", async () => {
expect(res.error[0].type).to.be.equal(ErrorType.AddedAPINotInOriginalSpec);
}
});

it("should not allow auth for VS project", async () => {
const inputs = {
platform: Platform.VS,
};
sandbox.stub(CopilotPluginHelper, "formatValidationErrors").resolves([]);
sandbox.stub(CopilotPluginHelper, "logValidationResults").resolves();
sandbox.stub(SpecParser.prototype, "validate").resolves({
status: ValidationStatus.Valid,
warnings: [],
errors: [],
specHash: "xxx",
});
sandbox.stub(SpecParser.prototype, "list").resolves({
APIs: [
{
api: "1",
server: "https://test",
operationId: "id1",
isValid: false,
reason: [ErrorType.AuthTypeIsNotSupported],
},
],
allAPICount: 1,
validAPICount: 0,
});

const res = await CopilotPluginHelper.listOperations(context, "", inputs, true, false, "");
expect(res.isOk()).to.be.true;
});
});

describe("SpecGenerator", async () => {
Expand Down

0 comments on commit 0715b5f

Please sign in to comment.