{"size": 2146, "ext": "js", "max_stars_repo_path": "test/jose/JWASpec.js", "max_stars_repo_name": "solid/jose", "max_stars_repo_stars_event_min_datetime": "2018-06-06T18:20:16.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-04T07:17:10.000Z", "max_issues_repo_path": "test/jose/JWASpec.js", "max_issues_repo_name": "solid/jose", "max_issues_repo_issues_event_min_datetime": "2019-09-11T15:03:46.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-09T14:44:19.000Z", "max_forks_repo_path": "test/jose/JWASpec.js", "max_forks_repo_name": "solid/jose", "max_forks_repo_forks_event_min_datetime": "2018-12-10T23:55:16.000Z", "max_forks_repo_forks_event_max_datetime": "2018-12-10T23:55:16.000Z"}
{"max_stars_count": 3, "max_issues_count": 11, "max_forks_count": 1, "avg_line_length": 26.825, "max_line_length": 364, "alphanum_fraction": 0.6640260951}
'use strict'

/**
 * Test dependencies
 */
const chai = require('chai')
const chaiAsPromised = require('chai-as-promised')

/**
 * Assertions
 */
chai.should()
chai.use(chaiAsPromised)
let expect = chai.expect

/**
 * Code under test
 */
const { NotSupportedError } = require('../../src/errors')
const JWA = require('../../src/jose/JWA')
const { getPublicKey, getPrivateKey } = require('../keys')

/**
 * Tests
 */
describe('JWA', () => {
  const alg = { name: 'RSASSA-PKCS1-v1_5', hash: { name: 'SHA-256' } }

  const data ='signed with Chrome webcrypto'
  const signature = 'VLW6eetMx2aufbDYXr7zydty4z02wu0O-Mx4bfnc5VAsMFaFYIFV1UYTfgCgWxK5yGa0tUUborW9brxwfF050FuOtsBXp8FvWAX0bMiWhUSQ0Bub3tW94JzifEGyRUc_840DftHtLbPw_8L1K5R7YazvqN0sukjCHQmrZ322J1-jUAPQuLgwcocHb3ImGRzqUhIxcRT7O5POB4YPvcn98XjsOuuUG8zppR8b3xwK1p9tuu9HfhI_b8Zz4u2RGgx4OKYNw0ELcpWR__Jhvv_K25BT7vC2UqXldpIdX39MvPeK_kgS-yp2nOVCCGo3alPo6hfDoKeFDrV-BSSdAlGQUw'

  let publicKey, privateKey

  describe('sign', () => {
    before(async () => {
      privateKey = await getPrivateKey()
    })

    it('should return a promise', () => {
      return JWA.sign('RS256', privateKey, 'data')
        .should.be.fulfilled
    })

    it('should reject unsupported algorithm', () => {
      return JWA.sign('RS257', privateKey, 'data')
        .should.be.rejectedWith(NotSupportedError)
    })

    it('should reject mismatching key')

    it('should resolve a signature', () => {
      return JWA.sign('RS256', privateKey, data)
        .should.eventually.equal(signature)
    })
  })

  describe('verify', () => {
    before(async () => {
      publicKey = await getPublicKey()
    })

    it('should return a promise', () => {
      JWA.verify('RS256', publicKey, signature, data)
        .should.be.fulfilled
    })

    it('should reject unsupported algorithm', () => {
      return JWA.verify('RS257', privateKey, signature, data)
        .should.be.rejectedWith(NotSupportedError)
    })

    it('should reject mismatching key')

    it('should resolve a boolean', () => {
      return JWA.verify('RS256', publicKey, signature, data)
        .should.eventually.equal(true)
    })
  })
})
