Skip to content

Commit

Permalink
fix: fix inject auth action (#12735)
Browse files Browse the repository at this point in the history
* fix: fix inject auth action

* test: update ut

* test: update ut
  • Loading branch information
KennethBWSong authored Nov 15, 2024
1 parent ce149bb commit 8abc127
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
10 changes: 8 additions & 2 deletions packages/fx-core/src/component/configManager/actionInjector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ export class ActionInjector {
if (forceToAddNew) {
return uses;
} else {
return uses !== actionName && uses !== "apiKey/register";
return (
uses != "apiKey/register" &&
(uses !== actionName || item.get("with")?.get("name") !== authName)
);
}
});
const existingConfigurationIdEnvNames: string[] = provisionNode.items
Expand Down Expand Up @@ -145,7 +148,10 @@ export class ActionInjector {
if (forceToAddNew) {
return uses;
} else {
return uses !== actionName && uses !== "oauth/register";
return (
uses != "oauth/register" &&
(uses !== actionName || item.get("with")?.get("name") !== authName)
);
}
});
const existingRegistrationIdEnvNames: string[] = provisionNode.items
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ describe("ActionInjector", () => {
writeToEnvironmentFile:
teamsAppId: TEAMS_APP_ID
- uses: apiKey/register
- uses: oauth/register
- uses: oauth/register
with:
name: oauthName
- uses: teamsApp/create
with:
name: oAuth2AuthCode
`;

sandbox.stub(fs, "readFile").resolves(ymlContent as any);
Expand All @@ -79,6 +86,7 @@ describe("ActionInjector", () => {
registrationIdEnvName: "TEST_AUTH_CONFIGURATION_ID",
});
assert.isTrue(writeStub.args[0][1].includes("oauth/register"));
assert.isTrue(writeStub.args[0][1].includes("oauthName"));
assert.isFalse(writeStub.args[0][1].includes("apiKey/register"));
});

Expand Down
40 changes: 39 additions & 1 deletion packages/fx-core/tests/core/FxCore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3496,6 +3496,17 @@ describe("copilotPlugin", async () => {
registrationId: "BEARERAUTH1_REGISTRATION_ID",
},
},
{
uses: "apiKey/register",
with: {
name: "api_key2",
appId: "${{TEAMS_APP_ID}}",
apiSpecPath: "./appPackage/apiSpecificationFiles/openapi.json",
},
writeToEnvironmentFile: {
registrationId: "API_KEY1_REGISTRATION_ID",
},
},
{
uses: "teamsApp/zipAppPackage",
with: {
Expand Down Expand Up @@ -3598,7 +3609,7 @@ describe("copilotPlugin", async () => {
{
uses: "apiKey/register",
writeToEnvironmentFile: {
registrationId: "BEARERAUTH1_REGISTRATION_ID",
registrationId: "BEARERAUTH1_REGISTRATION_ID1",
},
},
{
Expand Down Expand Up @@ -3644,6 +3655,12 @@ describe("copilotPlugin", async () => {
registrationId: "BEARERAUTH1_REGISTRATION_ID",
},
},
{
uses: "apiKey/register",
writeToEnvironmentFile: {
registrationId: "BEARERAUTH1_REGISTRATION_ID1",
},
},
{
uses: "teamsApp/zipAppPackage",
with: {
Expand Down Expand Up @@ -3795,6 +3812,16 @@ describe("copilotPlugin", async () => {
registrationId: "BEARERAUTH1_REGISTRATION_ID",
},
},
{
uses: "apiKey/register",
with: {
appId: "${{TEAMS_APP_ID}}",
apiSpecPath: "./appPackage/apiSpecificationFiles/openapi.json",
},
writeToEnvironmentFile: {
registrationId: "API_KEY1_REGISTRATION_ID",
},
},
{
uses: "teamsApp/zipAppPackage",
with: {
Expand Down Expand Up @@ -4242,6 +4269,17 @@ describe("copilotPlugin", async () => {
registrationId: "BEARERAUTH1_REGISTRATION_ID",
},
},
{
uses: "apiKey/register",
with: {
name: "api_key_unknown",
appId: "${{TEAMS_APP_ID}}",
apiSpecPath: ".appPackage/apiSpecificationFiles/openapi.json",
},
writeToEnvironmentFile: {
registrationId: "API_KEY_UNKNOWN_REGISTRATION_ID",
},
},
{
uses: "teamsApp/zipAppPackage",
with: {
Expand Down

0 comments on commit 8abc127

Please sign in to comment.