<commit_before>fs = require 'fs'
Helper = require('wire-context-helper').Helper()
TestHelper = require('wire-context-helper').Helper('tests')
APIMeta = require Helper.model('APIMeta')
Credential = require Helper.model('Credential')
Request = require Helper.model('ItemLookupRequest')
Signer = require Helper.service('RequestSigner')

chai = require 'chai'
assert = chai.assert
promised = require 'chai-as-promised'
chai.use promised

describe 'RequestSigner', ->
  apiMeta = null
  credential = null
  signer = new Signer()

  before (done) ->
    apiMeta = new APIMeta()
    fs.readFile TestHelper.path('configs/test-credentials.json'), encoding: 'utf8', (err, config) ->
      return done(err) if err
      c = JSON.parse config
      credential = new Credential c.accessKey, c.secretKey, c.associateTag
      done()

  it 'should sign requests properly', ->
    request = new Request(apiMeta, credential, ItemId: '0124166903', '2014-10-31T13:26:16+01:00')
    assert.equal signer.sign(request), 'http://webservices.amazon.com/onca/xml?AWSAccessKeyId=<KEY>&AssociateTag=tellico-20&ItemId=0124166903&Operation=ItemLookup&Service=AWSECommerceService&Timestamp=2014-10-31T13%3A26%3A16%2B01%3A00&Version=2011-08-01&Signature=YCfw9%2FTQ60OWCbq0IIJCkwe1WOetsQ4S002yEwC8JNs%3D'
<commit_msg>Use hashes on configuration keys.<commit_after>fs = require 'fs'
Helper = require('wire-context-helper').Helper()
TestHelper = require('wire-context-helper').Helper('tests')
APIMeta = require Helper.model('APIMeta')
Credential = require Helper.model('Credential')
Request = require Helper.model('ItemLookupRequest')
Signer = require Helper.service('RequestSigner')

chai = require 'chai'
assert = chai.assert
promised = require 'chai-as-promised'
chai.use promised

describe 'RequestSigner', ->
  apiMeta = null
  credential = null
  signer = new Signer()

  before (done) ->
    apiMeta = new APIMeta()
    fs.readFile TestHelper.path('configs/test-credentials.json'), encoding: 'utf8', (err, config) ->
      return done(err) if err
      c = JSON.parse config
      credential = new Credential c['accessKey'], c['secretKey'], c['associateTag']
      done()

  it 'should sign requests properly', ->
    request = new Request(apiMeta, credential, ItemId: '0124166903', '2014-10-31T13:26:16+01:00')
    assert.equal signer.sign(request), 'http://webservices.amazon.com/onca/xml?AWSAccessKeyId=<KEY>&AssociateTag=tellico-20&ItemId=0124166903&Operation=ItemLookup&Service=AWSECommerceService&Timestamp=2014-10-31T13%3A26%3A16%2B01%3A00&Version=2011-08-01&Signature=YCfw9%2FTQ60OWCbq0IIJCkwe1WOetsQ4S002yEwC8JNs%3D'

{'fraction_non_alphanumeric': 0.13928434013081956, 'fraction_numerical': 0.06387071950750288, 'mean_word_length': 5.6157760814249365, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7142177', 'n_tokens_mistral': 993, 'n_tokens_neox': 904, 'n_words': 160}