File: swd_spec.rb

package info (click to toggle)
ruby-swd 2.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 184 kB
  • sloc: ruby: 510; makefile: 6
file content (119 lines) | stat: -rw-r--r-- 3,728 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
require 'spec_helper'

describe SWD do
  after { SWD.debugging = false }

  its(:logger) { should be_a Logger }
  its(:debugging?) { should == false }
  its(:cache) { should be_a SWD::Cache }

  describe '#discover!' do
    it 'should return SWD::Response' do
      mock_json "https://example.com/.well-known/simple-web-discovery", 'success', :query => {
        :principal => 'mailto:joe@example.com',
        :service => 'urn:adatum.com:calendar'
      } do
        SWD.discover!(
          :principal => 'mailto:joe@example.com',
          :service => 'urn:adatum.com:calendar',
          :host => 'example.com'
        ).should be_a SWD::Response
      end
    end

    context 'when port specified' do
      it 'should use it' do
        mock_json "https://example.com:8080/.well-known/simple-web-discovery", 'success', :query => {
          :principal => 'mailto:joe@example.com',
          :service => 'urn:adatum.com:calendar'
        } do
          SWD.discover!(
            :principal => 'mailto:joe@example.com',
            :service => 'urn:adatum.com:calendar',
            :host => 'example.com',
            :port => 8080
          ).should be_a SWD::Response
        end
      end

      context 'when redirected to different host' do
        context 'with port' do
          it 'should success' do
            mock_json "https://example.com:8080/.well-known/simple-web-discovery", 'redirect_with_port', :query => {
              :principal => 'mailto:joe@example.com',
              :service => 'urn:adatum.com:calendar'
            } do
              mock_json "https://swd.proseware.com:8080/swd_server", 'success', :query => {
                :principal => 'mailto:joe@example.com',
                :service => 'urn:adatum.com:calendar'
              } do
                SWD.discover!(
                  :principal => 'mailto:joe@example.com',
                  :service => 'urn:adatum.com:calendar',
                  :host => 'example.com',
                  :port => 8080
                ).should be_a SWD::Response
              end
            end
          end
        end

        context 'without port' do
          it 'should success' do
            mock_json "https://example.com:8080/.well-known/simple-web-discovery", 'redirect', :query => {
              :principal => 'mailto:joe@example.com',
              :service => 'urn:adatum.com:calendar'
            } do
              mock_json "https://swd.proseware.com/swd_server", 'success', :query => {
                :principal => 'mailto:joe@example.com',
                :service => 'urn:adatum.com:calendar'
              } do
                SWD.discover!(
                  :principal => 'mailto:joe@example.com',
                  :service => 'urn:adatum.com:calendar',
                  :host => 'example.com',
                  :port => 8080
                ).should be_a SWD::Response
              end
            end
          end
        end
      end
    end
  end

  describe '.debug!' do
    before { SWD.debug! }
    its(:debugging?) { should == true }
  end

  describe '.debug' do
    it 'should enable debugging within given block' do
      SWD.debug do
        SWD.debugging?.should == true
      end
      SWD.debugging?.should == false
    end

    it 'should not force disable debugging' do
      SWD.debug!
      SWD.debug do
        SWD.debugging?.should == true
      end
      SWD.debugging?.should == true
    end
  end

  describe '.http_client' do
    context 'with http_config' do
      before do
        SWD.http_config do |config|
          config.ssl.verify = false
        end
      end
      it 'should configure http_client' do
        SWD.http_client.ssl.verify.should be_falsy
      end
    end
  end
end