All files / test ProviderSpec.js

100% Statements 114/114
100% Branches 0/0
100% Functions 36/36
100% Lines 114/114
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249          1x 1x 1x 1x 1x         1x 1x 1x 1x         1x 1x 1x 1x 1x 1x 1x 1x 1x         1x         1x 1x 1x     1x           1x 1x 1x           1x 1x           1x 1x           1x 1x 1x 1x 1x 1x 1x             1x     1x 1x 1x 1x 1x 1x     1x 1x     1x 1x               1x     1x 1x 1x 1x 1x 1x     1x 1x     1x 1x               1x     1x 1x 1x 1x 1x 1x     1x 1x     1x 1x               1x     1x 1x 1x 1x 1x 1x     1x 1x     1x 1x               1x     1x 1x 1x 1x 1x 1x     1x 1x     1x 1x               1x     1x 1x 1x 1x 1x 1x     1x 1x     1x 1x         1x     1x 1x 1x 1x 1x 1x     1x 1x     1x 1x          
'use strict'
 
/**
 * Test dependencies
 */
const cwd = process.cwd()
const path = require('path')
const chai = require('chai')
const sinon = require('sinon')
const sinonChai = require('sinon-chai')
 
/**
 * Assertions
 */
chai.use(sinonChai)
chai.use(require('dirty-chai'))
chai.should()
let expect = chai.expect
 
/**
 * Code under test
 */
const Provider = require(path.join(cwd, 'src', 'Provider'))
const ProviderSchema = require(path.join(cwd, 'src', 'schemas', 'ProviderSchema'))
const AuthenticationRequest = require(path.join(cwd, 'src', 'handlers', 'AuthenticationRequest'))
const OpenIDConfigurationRequest = require(path.join(cwd, 'src', 'handlers', 'OpenIDConfigurationRequest'))
const DynamicRegistrationRequest = require(path.join(cwd, 'src', 'handlers', 'DynamicRegistrationRequest'))
const JWKSetRequest = require(path.join(cwd, 'src', 'handlers', 'JWKSetRequest'))
const TokenRequest = require(path.join(cwd, 'src', 'handlers', 'TokenRequest'))
const UserInfoRequest = require(path.join(cwd, 'src', 'handlers', 'UserInfoRequest'))
const RPInitiatedLogoutRequest = require(path.join(cwd, 'src', 'handlers', 'RPInitiatedLogoutRequest'))
 
/**
 * Tests
 */
describe('OpenID Connect Provider', () => {
 
  /**
   * Schema
   */
  describe('schema', () => {
    it('should reference the OpenID Connect Provider Schema', () => {
      Provider.schema.should.equal(ProviderSchema)
    })
 
    it('should be an instance of JSONSchema')
  })
 
  /**
   * Constructor
   */
  describe('constructor', () => {
    it('should set the host')
    it('should call initialize on the instance')
  })
 
  /**
   * Initialize
   */
  describe('initialize', () => {
    it('should initialize based on the defined schema')
  })
 
  /**
   * Validate
   */
  describe('validate', () => {
    it('should initialize based on the defined schema')
  })
 
  /**
   * Inject
   */
  describe('inject', () => {
    it('should set non-enumerable property', () => {
      let provider = new Provider({ issuer: 'https://forge.anvil.io' })
      expect(provider.injected).to.be.undefined()
      provider.inject({ injected: true })
      provider.injected.should.equal(true)
      Object.keys(provider).should.not.include('injected')
    })
  })
 
  /**
   * Authorize
   */
  describe('authorize endpoint', () => {
    let req, res, provider
 
    before(() => {
      req = {}
      res = {}
      sinon.stub(AuthenticationRequest, 'handle')
      provider = new Provider({}, {}, {})
      provider.authorize(req, res, provider)
    })
 
    after(() => {
      AuthenticationRequest.handle.restore()
    })
 
    it('should invoke the AuthenticationRequest handler', () => {
      AuthenticationRequest.handle.should.have.been
        .calledWith(req, res, provider)
    })
  })
 
  /**
   * Discover
   */
  describe('discover endpoint', () => {
    let req, res, provider
 
    before(() => {
      req = {}
      res = {}
      sinon.stub(OpenIDConfigurationRequest, 'handle')
      provider = new Provider({}, {}, {})
      provider.discover(req, res, provider)
    })
 
    after(() => {
      OpenIDConfigurationRequest.handle.restore()
    })
 
    it('should invoke the OpenIDConfigurationRequest handler', () => {
      OpenIDConfigurationRequest.handle.should.have.been
        .calledWith(req, res, provider)
    })
  })
 
  /**
   * JWKs
   */
  describe('jwks endpoint', () => {
    let req, res, provider
 
    before(() => {
      req = {}
      res = {}
      sinon.stub(JWKSetRequest, 'handle')
      provider = new Provider({}, {}, {})
      provider.jwks(req, res, provider)
    })
 
    after(() => {
      JWKSetRequest.handle.restore()
    })
 
    it('should invoke the JWKSetRequest handler', () => {
      JWKSetRequest.handle.should.have.been
        .calledWith(req, res, provider)
    })
  })
 
  /**
   * Register
   */
  describe('dynamic registration endpoint', () => {
    let req, res, provider
 
    before(() => {
      req = {}
      res = {}
      sinon.stub(DynamicRegistrationRequest, 'handle')
      provider = new Provider({}, {}, {})
      provider.register(req, res, provider)
    })
 
    after(() => {
      DynamicRegistrationRequest.handle.restore()
    })
 
    it('should invoke the DynamicRegistrationRequest handler', () => {
      DynamicRegistrationRequest.handle.should.have.been
        .calledWith(req, res, provider)
    })
  })
 
  /**
   * Token
   */
  describe('token endpoint', () => {
    let req, res, provider
 
    before(() => {
      req = {}
      res = {}
      sinon.stub(TokenRequest, 'handle')
      provider = new Provider({}, {}, {})
      provider.token(req, res, provider)
    })
 
    after(() => {
      TokenRequest.handle.restore()
    })
 
    it('should invoke the TokenRequest handler', () => {
      TokenRequest.handle.should.have.been
        .calledWith(req, res, provider)
    })
  })
 
  /**
   * UserInfo
   */
  describe('userinfo endpoint', () => {
    let req, res, provider
 
    before(() => {
      req = {}
      res = {}
      sinon.stub(UserInfoRequest, 'handle')
      provider = new Provider({}, {}, {})
      provider.userinfo(req, res, provider)
    })
 
    after(() => {
      UserInfoRequest.handle.restore()
    })
 
    it('should invoke the UserInfoRequest handler', () => {
      UserInfoRequest.handle.should.have.been
        .calledWith(req, res, provider)
    })
  })
 
  describe('logout', () => {
    let req, res, provider
 
    before(() => {
      req = {}
      res = {}
      sinon.stub(RPInitiatedLogoutRequest, 'handle')
      provider = new Provider({}, {}, {})
      provider.logout(req, res, provider)
    })
 
    after(() => {
      RPInitiatedLogoutRequest.handle.restore()
    })
 
    it('should invoke the RPInitiatedLogoutRequest handler', () => {
      RPInitiatedLogoutRequest.handle.should.have.been
        .calledWith(req, res, provider)
    })
  })
})