mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-01-29 15:44:26 +00:00
Promisify auth utils tests
This commit is contained in:
parent
2db1d84d3c
commit
0e2fb8c96c
@ -9,39 +9,36 @@ describe 'Utils:', ->
|
|||||||
|
|
||||||
describe '.getDashboardLoginURL()', ->
|
describe '.getDashboardLoginURL()', ->
|
||||||
|
|
||||||
it 'should eventually be a valid url', (done) ->
|
it 'should eventually be a valid url', ->
|
||||||
utils.getDashboardLoginURL('https://127.0.0.1:3000/callback').then (loginUrl) ->
|
utils.getDashboardLoginURL('https://127.0.0.1:3000/callback').then (loginUrl) ->
|
||||||
m.chai.expect ->
|
m.chai.expect ->
|
||||||
url.parse(loginUrl)
|
url.parse(loginUrl)
|
||||||
.to.not.throw(Error)
|
.to.not.throw(Error)
|
||||||
.nodeify(done)
|
|
||||||
|
|
||||||
it 'should eventually contain an https protocol', (done) ->
|
|
||||||
|
it 'should eventually contain an https protocol', ->
|
||||||
Promise.props
|
Promise.props
|
||||||
dashboardUrl: resin.settings.get('dashboardUrl')
|
dashboardUrl: resin.settings.get('dashboardUrl')
|
||||||
loginUrl: utils.getDashboardLoginURL('https://127.0.0.1:3000/callback')
|
loginUrl: utils.getDashboardLoginURL('https://127.0.0.1:3000/callback')
|
||||||
.then ({ dashboardUrl, loginUrl }) ->
|
.then ({ dashboardUrl, loginUrl }) ->
|
||||||
protocol = url.parse(loginUrl).protocol
|
protocol = url.parse(loginUrl).protocol
|
||||||
m.chai.expect(protocol).to.equal(url.parse(dashboardUrl).protocol)
|
m.chai.expect(protocol).to.equal(url.parse(dashboardUrl).protocol)
|
||||||
.nodeify(done)
|
|
||||||
|
|
||||||
it 'should correctly escape a callback url without a path', (done) ->
|
it 'should correctly escape a callback url without a path', ->
|
||||||
Promise.props
|
Promise.props
|
||||||
dashboardUrl: resin.settings.get('dashboardUrl')
|
dashboardUrl: resin.settings.get('dashboardUrl')
|
||||||
loginUrl: utils.getDashboardLoginURL('http://127.0.0.1:3000')
|
loginUrl: utils.getDashboardLoginURL('http://127.0.0.1:3000')
|
||||||
.then ({ dashboardUrl, loginUrl }) ->
|
.then ({ dashboardUrl, loginUrl }) ->
|
||||||
expectedUrl = "#{dashboardUrl}/login/cli/http%253A%252F%252F127.0.0.1%253A3000"
|
expectedUrl = "#{dashboardUrl}/login/cli/http%253A%252F%252F127.0.0.1%253A3000"
|
||||||
m.chai.expect(loginUrl).to.equal(expectedUrl)
|
m.chai.expect(loginUrl).to.equal(expectedUrl)
|
||||||
.nodeify(done)
|
|
||||||
|
|
||||||
it 'should correctly escape a callback url with a path', (done) ->
|
it 'should correctly escape a callback url with a path', ->
|
||||||
Promise.props
|
Promise.props
|
||||||
dashboardUrl: resin.settings.get('dashboardUrl')
|
dashboardUrl: resin.settings.get('dashboardUrl')
|
||||||
loginUrl: utils.getDashboardLoginURL('http://127.0.0.1:3000/callback')
|
loginUrl: utils.getDashboardLoginURL('http://127.0.0.1:3000/callback')
|
||||||
.then ({ dashboardUrl, loginUrl }) ->
|
.then ({ dashboardUrl, loginUrl }) ->
|
||||||
expectedUrl = "#{dashboardUrl}/login/cli/http%253A%252F%252F127.0.0.1%253A3000%252Fcallback"
|
expectedUrl = "#{dashboardUrl}/login/cli/http%253A%252F%252F127.0.0.1%253A3000%252Fcallback"
|
||||||
m.chai.expect(loginUrl).to.equal(expectedUrl)
|
m.chai.expect(loginUrl).to.equal(expectedUrl)
|
||||||
.nodeify(done)
|
|
||||||
|
|
||||||
describe '.isTokenValid()', ->
|
describe '.isTokenValid()', ->
|
||||||
|
|
||||||
@ -76,26 +73,24 @@ describe 'Utils:', ->
|
|||||||
|
|
||||||
describe 'given there was a token already', ->
|
describe 'given there was a token already', ->
|
||||||
|
|
||||||
beforeEach (done) ->
|
beforeEach ->
|
||||||
resin.auth.loginWithToken(tokens.janedoe.token).nodeify(done)
|
resin.auth.loginWithToken(tokens.janedoe.token)
|
||||||
|
|
||||||
it 'should preserve the old token', (done) ->
|
it 'should preserve the old token', ->
|
||||||
resin.auth.getToken().then (originalToken) ->
|
resin.auth.getToken().then (originalToken) ->
|
||||||
m.chai.expect(originalToken).to.equal(tokens.janedoe.token)
|
m.chai.expect(originalToken).to.equal(tokens.janedoe.token)
|
||||||
return utils.isTokenValid(tokens.johndoe.token)
|
return utils.isTokenValid(tokens.johndoe.token)
|
||||||
.then(resin.auth.getToken).then (currentToken) ->
|
.then(resin.auth.getToken).then (currentToken) ->
|
||||||
m.chai.expect(currentToken).to.equal(tokens.janedoe.token)
|
m.chai.expect(currentToken).to.equal(tokens.janedoe.token)
|
||||||
.nodeify(done)
|
|
||||||
|
|
||||||
describe 'given there was no token', ->
|
describe 'given there was no token', ->
|
||||||
|
|
||||||
beforeEach (done) ->
|
beforeEach ->
|
||||||
resin.auth.logout().nodeify(done)
|
resin.auth.logout()
|
||||||
|
|
||||||
it 'should stay without a token', (done) ->
|
it 'should stay without a token', ->
|
||||||
utils.isTokenValid(tokens.johndoe.token).then ->
|
utils.isTokenValid(tokens.johndoe.token).then ->
|
||||||
m.chai.expect(resin.token.get()).to.eventually.not.exist
|
m.chai.expect(resin.token.get()).to.eventually.not.exist
|
||||||
.nodeify(done)
|
|
||||||
|
|
||||||
describe 'given the token does authenticate with the server', ->
|
describe 'given the token does authenticate with the server', ->
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user