mirror of
https://github.com/cypress-io/cypress.git
synced 2026-04-24 07:59:12 -05:00
f89a8236a8
* desktop-gui: use authBegin api * server: add auth lib for in-browser auth * server: unneeded * server: send proper cors header, actually receive authinfo * desktop-gui: DASHBOARD_LOGIN * server: send both auth flows through dashboard login * server, desktop-gui: exchange code for token, move logic out of desktop gui, cache auth urls * server: cleanup * server: refresh token [wip] * server: cleanup * server: focus main window on login * server: focus cypress after login * server: fix * server: use id_token so Google Login works, fixes to fallback electron auth flow * desktop-gui: "Log In with GitHub" -> "Log In to Dashboard" * server: work without electron * server: what a bizarre function signature, but ok * server: unit test for new auth.js * driver, server: cleanup * server: use redirects instead of XHR * server: update api spec * add some tests for token refreshin * desktop-gui: update tests, cleanup * unit tests * add user unit tests * server: rely on dashboard to set us up with access_token, user profile, etc * server: cleanup * redirect errors too * server: don't worry about refresh tokens in TR * guard against null server * don't regenerate state * fix auth unit test * fall back to electron auth if native auth never opens * break out MarkdownRenderer component * warn if browser not opened, offer copyable url * remove electron fallback and all login window handling * update tests * send more feedback when authing * add success message when logging in * update tests to expect continue button, warnings * use :contains * send machineId, version, platform, arch with login * createSignout -> createLogout, get logoutUrl from /auth v2 endpoint * Change version queryParam to cypressVersion, keep platform as platform, don't bother sending arch * Change " Opening browser..." button to display " Browser failed to open" * "You are now logged in to the Cypress Dashboard as Zach Bloomquist." -> "You are now logged in as Zach Bloomquist." * POST /signout -> GET /logout * make fallback URL click-to-select * add tests for edge cases in browser launching * cleanup * logoutUrl -> dashboardLogoutUrl * getLogout -> postLogout * getLogout -> postLogout * send machineId with postLogout
86 lines
2.8 KiB
CoffeeScript
86 lines
2.8 KiB
CoffeeScript
require("../spec_helper")
|
|
|
|
api = require("#{root}lib/api")
|
|
cache = require("#{root}lib/cache")
|
|
user = require("#{root}lib/user")
|
|
errors = require("#{root}lib/errors")
|
|
|
|
describe "lib/user", ->
|
|
context ".get", ->
|
|
it "calls cache.getUser", ->
|
|
sinon.stub(cache, "getUser").resolves({name: "brian"})
|
|
|
|
user.get().then (user) ->
|
|
expect(user).to.deep.eq({name: "brian"})
|
|
|
|
context ".logOut", ->
|
|
it "calls api.postLogout + removes the session from cache", ->
|
|
sinon.stub(api, "postLogout").withArgs("abc-123").resolves()
|
|
sinon.stub(cache, "getUser").resolves({name: "brian", authToken: "abc-123"})
|
|
sinon.spy(cache, "removeUser")
|
|
|
|
user.logOut().then ->
|
|
expect(cache.removeUser).to.be.calledOnce
|
|
|
|
it "does not send to api.postLogout without a authToken", ->
|
|
sinon.spy(api, "postLogout")
|
|
sinon.stub(cache, "getUser").resolves({name: "brian"})
|
|
sinon.spy(cache, "removeUser")
|
|
|
|
user.logOut().then ->
|
|
expect(api.postLogout).not.to.be.called
|
|
expect(cache.removeUser).to.be.calledOnce
|
|
|
|
it "removes the session from cache even if api.postLogout rejects", ->
|
|
sinon.stub(api, "postLogout").withArgs("abc-123").rejects(new Error("ECONNREFUSED"))
|
|
sinon.stub(cache, "getUser").resolves({name: "brian", authToken: "abc-123"})
|
|
sinon.spy(cache, "removeUser")
|
|
|
|
user.logOut().catch ->
|
|
expect(cache.removeUser).to.be.calledOnce
|
|
|
|
context ".syncProfile", ->
|
|
it "calls api.getMe then saves user to cache", ->
|
|
sinon.stub(api, "getMe").resolves({
|
|
name: 'foo'
|
|
email: 'bar@baz'
|
|
})
|
|
sinon.stub(cache, "setUser").resolves()
|
|
|
|
user.syncProfile("foo-123", "bar-456")
|
|
.then ->
|
|
expect(api.getMe).to.be.calledWith("foo-123")
|
|
expect(cache.setUser).to.be.calledWith({
|
|
authToken: "foo-123"
|
|
name: "foo"
|
|
email: "bar@baz"
|
|
})
|
|
|
|
context ".getBaseLoginUrl", ->
|
|
it "calls api.getAuthUrls", ->
|
|
sinon.stub(api, "getAuthUrls").resolves({
|
|
"dashboardAuthUrl": "https://github.com/login"
|
|
})
|
|
|
|
user.getBaseLoginUrl().then (url) ->
|
|
expect(url).to.eq("https://github.com/login")
|
|
|
|
context ".ensureAuthToken", ->
|
|
it "returns authToken", ->
|
|
sinon.stub(cache, "getUser").resolves({name: "brian", authToken: "abc-123"})
|
|
|
|
user.ensureAuthToken().then (st) ->
|
|
expect(st).to.eq("abc-123")
|
|
|
|
it "throws NOT_LOGGED_IN when no authToken, tagged as api error", ->
|
|
sinon.stub(cache, "getUser").resolves(null)
|
|
|
|
user.ensureAuthToken()
|
|
.then ->
|
|
throw new Error("should have thrown an error")
|
|
.catch (err) ->
|
|
expectedErr = errors.get("NOT_LOGGED_IN")
|
|
expect(err.message).to.eq(expectedErr.message)
|
|
expect(err.isApiError).to.be.true
|
|
expect(err.type).to.eq(expectedErr.type)
|