-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes a recent regression in the login flow, and stops throwing enterprise-related errors for non-enterprise projects when the user is logged in. Also added unit tests for the `login` command.
- Loading branch information
Showing
9 changed files
with
150 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright (C) 2018-2020 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { expect } from "chai" | ||
import td from "testdouble" | ||
import tmp from "tmp-promise" | ||
import { ProjectConfig, defaultNamespace } from "../../../../src/config/project" | ||
import { exec } from "../../../../src/util/util" | ||
import { DEFAULT_API_VERSION } from "../../../../src/constants" | ||
import { TestGarden, withDefaultGlobalOpts, expectError } from "../../../helpers" | ||
const Auth = require("../../../../src/enterprise/auth") | ||
import { LoginCommand } from "../../../../src/commands/login" | ||
import stripAnsi from "strip-ansi" | ||
|
||
function makeCommandParams(garden: TestGarden) { | ||
const log = garden.log | ||
return { | ||
garden, | ||
log, | ||
headerLog: log, | ||
footerLog: log, | ||
args: {}, | ||
opts: withDefaultGlobalOpts({}), | ||
} | ||
} | ||
|
||
describe("LoginCommand", () => { | ||
let tmpDir: tmp.DirectoryResult | ||
let projectConfig: ProjectConfig | ||
const dummyDomain = "dummy-domain" | ||
|
||
before(async () => { | ||
tmpDir = await tmp.dir({ unsafeCleanup: true }) | ||
await exec("git", ["init"], { cwd: tmpDir.path }) | ||
|
||
projectConfig = { | ||
apiVersion: DEFAULT_API_VERSION, | ||
kind: "Project", | ||
name: "test", | ||
path: tmpDir.path, | ||
defaultEnvironment: "default", | ||
dotIgnoreFiles: [], | ||
environments: [{ name: "default", defaultNamespace, variables: {} }], | ||
providers: [{ name: "test" }], | ||
variables: {}, | ||
} | ||
}) | ||
|
||
beforeEach(async () => { | ||
td.replace(Auth, "login", async () => "dummy-auth-token") | ||
}) | ||
|
||
after(async () => { | ||
await tmpDir.cleanup() | ||
}) | ||
|
||
it("should log in if the project has a domain and an id", async () => { | ||
const config = { ...projectConfig, domain: dummyDomain, id: "dummy-id" } | ||
const garden = await TestGarden.factory(tmpDir.path, { config }) | ||
const command = new LoginCommand() | ||
await command.action(makeCommandParams(garden)) | ||
}) | ||
|
||
it("should log in if the project has a domain but no id", async () => { | ||
const config = { ...projectConfig, domain: dummyDomain } | ||
const garden = await TestGarden.factory(tmpDir.path, { config }) | ||
const command = new LoginCommand() | ||
await command.action(makeCommandParams(garden)) | ||
}) | ||
|
||
it("should throw if the project doesn't have a domain", async () => { | ||
const garden = await TestGarden.factory(tmpDir.path, { config: projectConfig }) | ||
const command = new LoginCommand() | ||
await expectError( | ||
() => command.action(makeCommandParams(garden)), | ||
(err) => expect(stripAnsi(err.message)).to.match(/Your project configuration does not specify a domain/) | ||
) | ||
}) | ||
}) |