Sha256: e68197e0121e732bb6390db70f0baab77c661035fe733a71dd4ea6441747203c

Contents?: true

Size: 1.9 KB

Versions: 1

Compression:

Stored size: 1.9 KB

Contents

#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "test_helper"
require "azure/core/auth/shared_key_lite"

describe Azure::Core::Auth::SharedKeyLite do
  subject { Azure::Core::Auth::SharedKeyLite.new "account-name", "YWNjZXNzLWtleQ==" }
  
  let(:method) { "POST" }
  let(:uri) { URI.parse "http://dummy.uri/resource" }
  let(:headers) do
    {
      "Content-MD5"=> "foo",
      "Content-Type"=> "foo",
      "Date"=> "foo"
    }
  end
  let(:headers_without_date) { 
    headers_without_date = headers.clone
    headers_without_date.delete "Date"
    headers_without_date
  }
  
  describe "sign" do
    it "creates a signature from the provided HTTP method, uri, and reduced set of standard headers" do
      subject.sign(method, uri, headers).must_equal "account-name:vVFnj/+27JFABZgpt5H8g/JVU2HuWFnjv5aeUIxQvBE="
    end

    it "ignores standard headers other than Content-MD5, Content-Type, and Date" do
      subject.sign(method, uri, headers.merge({"Content-Encoding"=> "foo"})).must_equal "account-name:vVFnj/+27JFABZgpt5H8g/JVU2HuWFnjv5aeUIxQvBE="
    end

    it "throws IndexError when there is no Date header" do
      assert_raises IndexError do
        subject.sign(method, uri, headers_without_date)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
azure-0.5.0 test/unit/core/auth/shared_key_lite_test.rb