<commit_before>helpers = require('../helpers')
AWS = helpers.AWS

describe 'AWS.EC2', ->

  ec2 = new AWS.EC2()

  describe 'proxy support', ->
    it 'always sets Host header to correct endpoint', ->
      helpers.mockHttpResponse 200, {}, ''
      ec2 = new AWS.EC2(httpOptions: proxy: 'http://__INVALID_HOSTNAME__:9999')
      ec2.makeRequest 'describeInstances', ->
        expect(@request.httpRequest.headers.Host).
          toEqual('ec2.mock-region.amazonaws.com')

  describe 'copySnapshot', ->
    it 'generates PresignedUrl and DestinationRegion parameters', ->
      spyOn(AWS.util.date, 'getDate').andReturn(new Date(0))
      helpers.mockHttpResponse 200, {}, ''
      params = SourceRegion: 'src-region', SourceSnapshotId: 'snap-123456789'
      ec2.copySnapshot params, ->
        parts = @request.httpRequest.body.split('&').sort()
        [
          'AWSAccessKeyId=akid',
          'Action=CopySnapshot',
          'DestinationRegion=mock-region',
          'PresignedUrl=https%3A%2F%2Fec2.src-region.amazonaws.com%2F%3F' +
            "Action%3DCopySnapshot%26DestinationRegion%3Dmock-region%26SourceRegion%3Dsrc-region" +
            "%26SourceSnapshotId%3Dsnap-123456789%26Version%3D#{ec2.api.apiVersion}" +
            "%26X-Amz-Algorithm%3DAWS4-HMAC-SHA256%26X-Amz-Credential%3Dakid%252F19700101" +
            "%252Fsrc-region%252Fec2%252Faws4_request%26X-Amz-Date%3D19700101T000000Z" +
            "%26X-Amz-Expires%3D3600%26X-Amz-Security-Token%3Dsession" +
            "%26X-Amz-Signature%3D2a09621aaae799a2a4f68d40e14d4d57f73227307c992615917acc097cb7400c" +
            "%26X-Amz-SignedHeaders%3Dhost",
          'SourceRegion=src-region',
          'SourceSnapshotId=snap-123456789'
        ].forEach (i) ->
          expect(parts).toContain(i)
<commit_msg>Revert "Update signature in EC2 test"<commit_after>helpers = require('../helpers')
AWS = helpers.AWS

describe 'AWS.EC2', ->

  ec2 = new AWS.EC2()

  describe 'proxy support', ->
    it 'always sets Host header to correct endpoint', ->
      helpers.mockHttpResponse 200, {}, ''
      ec2 = new AWS.EC2(httpOptions: proxy: 'http://__INVALID_HOSTNAME__:9999')
      ec2.makeRequest 'describeInstances', ->
        expect(@request.httpRequest.headers.Host).
          toEqual('ec2.mock-region.amazonaws.com')

  describe 'copySnapshot', ->
    it 'generates PresignedUrl and DestinationRegion parameters', ->
      spyOn(AWS.util.date, 'getDate').andReturn(new Date(0))
      helpers.mockHttpResponse 200, {}, ''
      params = SourceRegion: 'src-region', SourceSnapshotId: 'snap-123456789'
      ec2.copySnapshot params, ->
        parts = @request.httpRequest.body.split('&').sort()
        [
          'AWSAccessKeyId=akid',
          'Action=CopySnapshot',
          'DestinationRegion=mock-region',
          'PresignedUrl=https%3A%2F%2Fec2.src-region.amazonaws.com%2F%3F' +
            "Action%3DCopySnapshot%26DestinationRegion%3Dmock-region%26SourceRegion%3Dsrc-region" +
            "%26SourceSnapshotId%3Dsnap-123456789%26Version%3D#{ec2.api.apiVersion}" +
            "%26X-Amz-Algorithm%3DAWS4-HMAC-SHA256%26X-Amz-Credential%3Dakid%252F197<PASSWORD>" +
            "%252Fsrc-region%252Fec2%252Faws4_request%26X-Amz-Date%3D19700101T000000Z" +
            "%26X-Amz-Expires%3D3600%26X-Amz-Security-Token%3Dsession" +
            "%26X-Amz-Signature%3D014459362191e87b3b175e1e16d007c0c9aaa1fdb2743f8cebdfd8dea0fb0cc2" +
            "%26X-Amz-SignedHeaders%3Dhost",
          'SourceRegion=src-region',
          'SourceSnapshotId=snap-123456789'
        ].forEach (i) ->
          expect(parts).toContain(i)

{'fraction_non_alphanumeric': 0.1398834304746045, 'fraction_numerical': 0.09381071329447682, 'mean_word_length': 3.25, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3284252', 'n_tokens_mistral': 1425, 'n_tokens_neox': 1270, 'n_words': 143}