File: header_class_methods_test.rb

package info (click to toggle)
ruby-simple-oauth 0.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 372 kB
  • sloc: ruby: 1,722; makefile: 4; sh: 4
file content (56 lines) | stat: -rw-r--r-- 1,720 bytes parent folder | download
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
require "test_helper"

module SimpleOAuth
  # Tests for Header class methods.
  class HeaderClassMethodsTest < Minitest::Test
    include TestHelpers

    cover "SimpleOAuth::Header*"

    # .default_options tests

    def test_default_options_is_different_every_time
      first = SimpleOAuth::Header.default_options
      second = SimpleOAuth::Header.default_options

      refute_equal first, second
    end

    def test_default_options_is_used_for_new_headers
      header = SimpleOAuth::Header.new(:get, "https://photos.example.net/photos", {})

      assert_includes header.options.keys, :nonce
      assert_includes header.options.keys, :signature_method
      assert_includes header.options.keys, :timestamp
    end

    def test_default_options_includes_version_key
      header = SimpleOAuth::Header.new(:get, "https://photos.example.net/photos", {})

      assert_includes header.options.keys, :version
    end

    def test_default_options_includes_signature_method
      refute_nil SimpleOAuth::Header.default_options[:signature_method]
    end

    def test_default_options_includes_oauth_version
      refute_nil SimpleOAuth::Header.default_options[:version]
    end

    def test_default_options_nonce_is_32_hex_characters
      # RFC 5849 Section 3.3 - nonce is a random string
      nonce = SimpleOAuth::Header.default_options[:nonce]

      assert_match(/\A[0-9a-f]{32}\z/, nonce)
    end

    def test_default_options_timestamp_is_integer_string
      # RFC 5849 Section 3.3 - timestamp is seconds since epoch
      timestamp = SimpleOAuth::Header.default_options[:timestamp]

      assert_match(/\A\d+\z/, timestamp)
      assert_equal Time.now.to_i.to_s.length, timestamp.length
    end
  end
end