Skip to content

Commit

Permalink
SM-1227: Removed debug logging from Bitwarden SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
mzieniukbw committed Jun 11, 2024
1 parent 2ce923b commit bb10f4f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 60 deletions.
81 changes: 26 additions & 55 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ let setFailedMock: jest.SpyInstance;
let setSecretMock: jest.SpyInstance;
let exportVariableMock: jest.SpyInstance;
let setOutputMock: jest.SpyInstance;
let setDebugMock: jest.SpyInstance;

// Mock the Bitwarden SDK
const secretsClientMock = jest.fn();
Expand Down Expand Up @@ -54,7 +53,6 @@ describe("action", () => {
setSecretMock = jest.spyOn(core, "setSecret").mockImplementation();
exportVariableMock = jest.spyOn(core, "exportVariable").mockImplementation();
setOutputMock = jest.spyOn(core, "setOutput").mockImplementation();
setDebugMock = jest.spyOn(core, "isDebug").mockReturnValue(false);
});

describe("sets a failed status", () => {
Expand Down Expand Up @@ -173,7 +171,6 @@ describe("action", () => {
identityUrl: DEFAULT_IDENTITY_URL,
apiUrl: DEFAULT_API_URL,
} as ClientSettings,
false,
],
[
"base_url provided",
Expand All @@ -186,7 +183,6 @@ describe("action", () => {
identityUrl: "https://bitwarden.example.com/identity",
apiUrl: "https://bitwarden.example.com/api",
} as ClientSettings,
false,
],
[
"identity_url provided",
Expand All @@ -199,7 +195,6 @@ describe("action", () => {
identityUrl: "https://identity.bitwarden.example.com",
apiUrl: DEFAULT_API_URL,
} as ClientSettings,
false,
],
[
"api_url provided",
Expand All @@ -212,7 +207,6 @@ describe("action", () => {
identityUrl: DEFAULT_IDENTITY_URL,
apiUrl: "https://api.bitwarden.example.com",
} as ClientSettings,
false,
],
[
"api_url and identity_url provided",
Expand All @@ -225,58 +219,35 @@ describe("action", () => {
identityUrl: "https://identity.bitwarden.example.com",
apiUrl: "https://api.bitwarden.example.com",
} as ClientSettings,
false,
],
[
"debug logging enabled",
{
baseUrl: DEFAULT_BASE_URL,
identityUrl: DEFAULT_IDENTITY_URL,
apiUrl: DEFAULT_API_URL,
} as OptionalInputs,
])("%s", async (_, optionalInputs: OptionalInputs, expectedClientSettings: ClientSettings) => {
mockInputs({
accessToken: TEST_ACCESS_TOKEN,
secrets: [] as string[],
...optionalInputs,
} as Inputs);
mockSecretsGetByIdResponse({
success: true,
data: {
data: [],
},
});

await main.run();

expect(setFailedMock).not.toHaveBeenCalled();
expect(errorMock).not.toHaveBeenCalled();
expect(setSecretMock).not.toHaveBeenCalled();
expect(bitwardenClientMock).toHaveBeenCalledTimes(1);
expect(bitwardenClientMock).toHaveBeenCalledWith([
{
identityUrl: DEFAULT_IDENTITY_URL,
apiUrl: DEFAULT_API_URL,
deviceType: DeviceType.SDK,
userAgent: "bitwarden/sm-action",
...expectedClientSettings,
} as ClientSettings,
true,
],
])(
"%s",
async (
_,
optionalInputs: OptionalInputs,
expectedClientSettings: ClientSettings,
isDebugEnabled: boolean,
) => {
mockInputs({
accessToken: TEST_ACCESS_TOKEN,
secrets: [] as string[],
...optionalInputs,
} as Inputs);
mockSecretsGetByIdResponse({
success: true,
data: {
data: [],
},
});
setDebugMock.mockReturnValue(isDebugEnabled);

await main.run();

expect(setFailedMock).not.toHaveBeenCalled();
expect(errorMock).not.toHaveBeenCalled();
expect(setSecretMock).not.toHaveBeenCalled();
expect(bitwardenClientMock).toHaveBeenCalledTimes(1);
expect(bitwardenClientMock).toHaveBeenCalledWith([
{
deviceType: DeviceType.SDK,
userAgent: "bitwarden/sm-action",
...expectedClientSettings,
} as ClientSettings,
isDebugEnabled ? LogLevel.Debug : LogLevel.Info,
]);
},
);
LogLevel.Info,
]);
});
});

describe("sets secrets", () => {
Expand Down
3 changes: 1 addition & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ async function getBitwardenClient(inputs: Inputs): Promise<BitwardenClient> {
deviceType: DeviceType.SDK,
};

const logLevel = core.isDebug() ? LogLevel.Debug : LogLevel.Info;

const client = new BitwardenClient(settings, logLevel);
const client = new BitwardenClient(settings, LogLevel.Info);
const result = await client.loginWithAccessToken(inputs.accessToken);
if (!result.success) {
throw Error(`Authentication with Bitwarden failed.\nError: ${result.errorMessage}`);
Expand Down

0 comments on commit bb10f4f

Please sign in to comment.