shibkit-meta_meta 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +21 -0
  4. data/Gemfile.lock +52 -0
  5. data/Icon.png +0 -0
  6. data/LICENSE.txt +177 -0
  7. data/README.md +789 -0
  8. data/Rakefile +38 -0
  9. data/VERSION +1 -0
  10. data/examples/biggest_entity_id.rb +4 -0
  11. data/lib/shibkit/meta_meta.rb +600 -0
  12. data/lib/shibkit/meta_meta/attribute.rb +73 -0
  13. data/lib/shibkit/meta_meta/config.rb +463 -0
  14. data/lib/shibkit/meta_meta/contact.rb +85 -0
  15. data/lib/shibkit/meta_meta/data/default_metadata/example_federation_metadata.xml +168 -0
  16. data/lib/shibkit/meta_meta/data/default_metadata/local_metadata.xml +66 -0
  17. data/lib/shibkit/meta_meta/data/default_metadata/uncommon_federation_metadata.xml +115 -0
  18. data/lib/shibkit/meta_meta/data/default_metadata_cache.yml +166 -0
  19. data/lib/shibkit/meta_meta/data/dev_sources.yml +86 -0
  20. data/lib/shibkit/meta_meta/data/real_sources.yml +163 -0
  21. data/lib/shibkit/meta_meta/entity.rb +219 -0
  22. data/lib/shibkit/meta_meta/federation.rb +161 -0
  23. data/lib/shibkit/meta_meta/idp.rb +81 -0
  24. data/lib/shibkit/meta_meta/logo.rb +216 -0
  25. data/lib/shibkit/meta_meta/metadata_item.rb +244 -0
  26. data/lib/shibkit/meta_meta/mixin/cached_downloads.rb +127 -0
  27. data/lib/shibkit/meta_meta/mixin/xpath_chores.rb +111 -0
  28. data/lib/shibkit/meta_meta/organisation.rb +73 -0
  29. data/lib/shibkit/meta_meta/provider.rb +195 -0
  30. data/lib/shibkit/meta_meta/provisioning/base.rb +33 -0
  31. data/lib/shibkit/meta_meta/requested_attribute.rb +29 -0
  32. data/lib/shibkit/meta_meta/service.rb +94 -0
  33. data/lib/shibkit/meta_meta/source.rb +558 -0
  34. data/lib/shibkit/meta_meta/sp.rb +79 -0
  35. data/shibkit-meta_meta.gemspec +154 -0
  36. data/spec/meta_meta/attribute/token +0 -0
  37. data/spec/meta_meta/config/autoloading_and_refreshing_spec.rb +72 -0
  38. data/spec/meta_meta/config/code_nspec.rb +13 -0
  39. data/spec/meta_meta/config/configuration_spec.rb +30 -0
  40. data/spec/meta_meta/config/creation_spec.rb +43 -0
  41. data/spec/meta_meta/config/downloading_and_caching_settings_spec.rb +216 -0
  42. data/spec/meta_meta/config/env_platform_settings.rb +129 -0
  43. data/spec/meta_meta/config/filtering_settings_spec.rb +123 -0
  44. data/spec/meta_meta/config/init.rb +8 -0
  45. data/spec/meta_meta/config/logger_settings_spec.rb +91 -0
  46. data/spec/meta_meta/config/smartcache_settings_spec.rb +110 -0
  47. data/spec/meta_meta/config/source_file_settings_spec.rb +99 -0
  48. data/spec/meta_meta/config/tagging_settings_spec.rb +81 -0
  49. data/spec/meta_meta/config/working_directory_settings_spec.rb +106 -0
  50. data/spec/meta_meta/config/xml_processing_settings_spec.rb +75 -0
  51. data/spec/meta_meta/contact/contact_oldspec.rb +0 -0
  52. data/spec/meta_meta/entity/entity_oldspec.rb +53 -0
  53. data/spec/meta_meta/federation/federation_oldspec.rb +0 -0
  54. data/spec/meta_meta/idp/token +0 -0
  55. data/spec/meta_meta/logo/token +0 -0
  56. data/spec/meta_meta/meta_meta/cache_example.yaml +141284 -0
  57. data/spec/meta_meta/meta_meta/meta_meta_spec.rb +269 -0
  58. data/spec/meta_meta/meta_meta/saved_sources.yaml +46 -0
  59. data/spec/meta_meta/metadata_item/token +0 -0
  60. data/spec/meta_meta/organisation/organisation_oldspec.rb +0 -0
  61. data/spec/meta_meta/provider/token +0 -0
  62. data/spec/meta_meta/requested_attribute/token +0 -0
  63. data/spec/meta_meta/service/token +0 -0
  64. data/spec/meta_meta/source/application_extras_spec.rb +234 -0
  65. data/spec/meta_meta/source/conversion_spec.rb +75 -0
  66. data/spec/meta_meta/source/creation_spec.rb +0 -0
  67. data/spec/meta_meta/source/downloads_and_caching_spec.rb +0 -0
  68. data/spec/meta_meta/source/federation_information_spec.rb +11 -0
  69. data/spec/meta_meta/source/fixtures.rb +24 -0
  70. data/spec/meta_meta/source/init.rb +1 -0
  71. data/spec/meta_meta/source/loading_and_saving_spec.rb +0 -0
  72. data/spec/meta_meta/source/metadata_details_spec.rb +0 -0
  73. data/spec/meta_meta/source/metadata_integrity_spec.rb +0 -0
  74. data/spec/meta_meta/source/selection_spec.rb +0 -0
  75. data/spec/meta_meta/source/source_oldspec.rb +353 -0
  76. data/spec/meta_meta/source/xml_parsing_spec.rb +0 -0
  77. data/spec/meta_meta/sp/token +0 -0
  78. data/spec/meta_meta/template +2 -0
  79. data/spec/moi/config_spec.rb +0 -0
  80. data/spec/spec.opts +1 -0
  81. data/spec/spec_helper.rb +25 -0
  82. data/spec/support/supply_xml.rb +0 -0
  83. metadata +320 -0
@@ -0,0 +1,79 @@
1
+ ## @author Pete Birkinshaw (<pete@digitalidentitylabs.com>)
2
+ ## Copyright: Copyright (c) 2011 Digital Identity Ltd.
3
+ ## License: Apache License, Version 2.0
4
+
5
+ ## Licensed under the Apache License, Version 2.0 (the "License");
6
+ ## you may not use this file except in compliance with the License.
7
+ ## You may obtain a copy of the License at
8
+ ##
9
+ ## http://www.apache.org/licenses/LICENSE-2.0
10
+ ##
11
+ ## Unless required by applicable law or agreed to in writing, software
12
+ ## distributed under the License is distributed on an "AS IS" BASIS,
13
+ ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ ## See the License for the specific language governing permissions and
15
+ ## limitations under the License.
16
+ ##
17
+
18
+ module Shibkit
19
+ class MetaMeta
20
+
21
+ require 'shibkit/meta_meta/provider'
22
+
23
+ ## Class to represent an SP
24
+ class SP < Provider
25
+
26
+
27
+ require 'shibkit/meta_meta/service'
28
+ require 'shibkit/meta_meta/requested_attribute'
29
+
30
+ ## Element and attribute used to select XML for new objects
31
+ ROOT_ELEMENT = 'EntityDescriptor'
32
+ TARGET_ATTR = 'entityID'
33
+ REQUIRED_QUACKS = [:entity_uri, :valid?]
34
+
35
+ MDUI_ROOT = 'SPSSODescriptor'
36
+
37
+
38
+ attr_accessor :services
39
+
40
+ attr_accessor :default_service
41
+
42
+ attr_accessor :protocols
43
+
44
+ private
45
+
46
+ def parse_xml
47
+
48
+ super
49
+
50
+ @valid = @noko.xpath('xmlns:SPSSODescriptor[1]').empty? ? false : true
51
+
52
+ proto_set = @noko.xpath('xmlns:SPSSODescriptor/@protocolSupportEnumeration')[0]
53
+ @protocols = proto_set.value.split(' ') if proto_set
54
+
55
+ ## Include services objects
56
+ @services ||= Array.new
57
+ @noko.xpath("xmlns:SPSSODescriptor/xmlns:AttributeConsumingService").each do |sx|
58
+
59
+ service = Shibkit::MetaMeta::Service.new(sx).filter
60
+
61
+ next unless service
62
+
63
+ @services << service
64
+ @default_service = service if service.default?
65
+
66
+ end
67
+
68
+ @services.sort! { |a,b| a.index <=> b.index }
69
+ @default_service = @services[0] unless @default_service
70
+
71
+ log.debug " Derived SP from XML" if filter
72
+
73
+ end
74
+
75
+ end
76
+
77
+
78
+ end
79
+ end
@@ -0,0 +1,154 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{shibkit-meta_meta}
8
+ s.version = "0.2.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{Pete Birkinshaw}]
12
+ s.date = %q{2011-11-07}
13
+ s.description = %q{Utilities for friendly handling of Shibboleth/SAML2 metadata. Easily download and parse metadata XML into Ruby objects.}
14
+ s.email = %q{gems@digitalidentitylabs.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "Icon.png",
25
+ "LICENSE.txt",
26
+ "README.md",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "examples/biggest_entity_id.rb",
30
+ "lib/shibkit/meta_meta.rb",
31
+ "lib/shibkit/meta_meta/attribute.rb",
32
+ "lib/shibkit/meta_meta/config.rb",
33
+ "lib/shibkit/meta_meta/contact.rb",
34
+ "lib/shibkit/meta_meta/data/default_metadata/example_federation_metadata.xml",
35
+ "lib/shibkit/meta_meta/data/default_metadata/local_metadata.xml",
36
+ "lib/shibkit/meta_meta/data/default_metadata/uncommon_federation_metadata.xml",
37
+ "lib/shibkit/meta_meta/data/default_metadata_cache.yml",
38
+ "lib/shibkit/meta_meta/data/dev_sources.yml",
39
+ "lib/shibkit/meta_meta/data/real_sources.yml",
40
+ "lib/shibkit/meta_meta/entity.rb",
41
+ "lib/shibkit/meta_meta/federation.rb",
42
+ "lib/shibkit/meta_meta/idp.rb",
43
+ "lib/shibkit/meta_meta/logo.rb",
44
+ "lib/shibkit/meta_meta/metadata_item.rb",
45
+ "lib/shibkit/meta_meta/mixin/cached_downloads.rb",
46
+ "lib/shibkit/meta_meta/mixin/xpath_chores.rb",
47
+ "lib/shibkit/meta_meta/organisation.rb",
48
+ "lib/shibkit/meta_meta/provider.rb",
49
+ "lib/shibkit/meta_meta/provisioning/base.rb",
50
+ "lib/shibkit/meta_meta/requested_attribute.rb",
51
+ "lib/shibkit/meta_meta/service.rb",
52
+ "lib/shibkit/meta_meta/source.rb",
53
+ "lib/shibkit/meta_meta/sp.rb",
54
+ "shibkit-meta_meta.gemspec",
55
+ "spec/meta_meta/attribute/token",
56
+ "spec/meta_meta/config/autoloading_and_refreshing_spec.rb",
57
+ "spec/meta_meta/config/code_nspec.rb",
58
+ "spec/meta_meta/config/configuration_spec.rb",
59
+ "spec/meta_meta/config/creation_spec.rb",
60
+ "spec/meta_meta/config/downloading_and_caching_settings_spec.rb",
61
+ "spec/meta_meta/config/env_platform_settings.rb",
62
+ "spec/meta_meta/config/filtering_settings_spec.rb",
63
+ "spec/meta_meta/config/init.rb",
64
+ "spec/meta_meta/config/logger_settings_spec.rb",
65
+ "spec/meta_meta/config/smartcache_settings_spec.rb",
66
+ "spec/meta_meta/config/source_file_settings_spec.rb",
67
+ "spec/meta_meta/config/tagging_settings_spec.rb",
68
+ "spec/meta_meta/config/working_directory_settings_spec.rb",
69
+ "spec/meta_meta/config/xml_processing_settings_spec.rb",
70
+ "spec/meta_meta/contact/contact_oldspec.rb",
71
+ "spec/meta_meta/entity/entity_oldspec.rb",
72
+ "spec/meta_meta/federation/federation_oldspec.rb",
73
+ "spec/meta_meta/idp/token",
74
+ "spec/meta_meta/logo/token",
75
+ "spec/meta_meta/meta_meta/cache_example.yaml",
76
+ "spec/meta_meta/meta_meta/meta_meta_spec.rb",
77
+ "spec/meta_meta/meta_meta/saved_sources.yaml",
78
+ "spec/meta_meta/metadata_item/token",
79
+ "spec/meta_meta/organisation/organisation_oldspec.rb",
80
+ "spec/meta_meta/provider/token",
81
+ "spec/meta_meta/requested_attribute/token",
82
+ "spec/meta_meta/service/token",
83
+ "spec/meta_meta/source/application_extras_spec.rb",
84
+ "spec/meta_meta/source/conversion_spec.rb",
85
+ "spec/meta_meta/source/creation_spec.rb",
86
+ "spec/meta_meta/source/downloads_and_caching_spec.rb",
87
+ "spec/meta_meta/source/federation_information_spec.rb",
88
+ "spec/meta_meta/source/fixtures.rb",
89
+ "spec/meta_meta/source/init.rb",
90
+ "spec/meta_meta/source/loading_and_saving_spec.rb",
91
+ "spec/meta_meta/source/metadata_details_spec.rb",
92
+ "spec/meta_meta/source/metadata_integrity_spec.rb",
93
+ "spec/meta_meta/source/selection_spec.rb",
94
+ "spec/meta_meta/source/source_oldspec.rb",
95
+ "spec/meta_meta/source/xml_parsing_spec.rb",
96
+ "spec/meta_meta/sp/token",
97
+ "spec/meta_meta/template",
98
+ "spec/moi/config_spec.rb",
99
+ "spec/spec.opts",
100
+ "spec/spec_helper.rb",
101
+ "spec/support/supply_xml.rb"
102
+ ]
103
+ s.homepage = %q{https://github.com/Digital-Identity-Labs/shibkit-meta_meta}
104
+ s.licenses = [%q{Apache 2.0}]
105
+ s.require_paths = [%q{lib}]
106
+ s.rubygems_version = %q{1.8.8}
107
+ s.summary = %q{Downloads and parses Shibboleth (SAML2) metadata.}
108
+
109
+ if s.respond_to? :specification_version then
110
+ s.specification_version = 3
111
+
112
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
113
+ s.add_runtime_dependency(%q<rake>, [">= 0"])
114
+ s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
115
+ s.add_runtime_dependency(%q<rest-client>, [">= 0"])
116
+ s.add_runtime_dependency(%q<rest-client-components>, [">= 0"])
117
+ s.add_runtime_dependency(%q<rack-cache>, [">= 0"])
118
+ s.add_runtime_dependency(%q<addressable>, [">= 0"])
119
+ s.add_runtime_dependency(%q<chunky_png>, [">= 0"])
120
+ s.add_runtime_dependency(%q<dimensions>, [">= 0"])
121
+ s.add_runtime_dependency(%q<json>, [">= 0"])
122
+ s.add_development_dependency(%q<rspec>, ["~> 2.7.0"])
123
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
124
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
125
+ else
126
+ s.add_dependency(%q<rake>, [">= 0"])
127
+ s.add_dependency(%q<nokogiri>, [">= 0"])
128
+ s.add_dependency(%q<rest-client>, [">= 0"])
129
+ s.add_dependency(%q<rest-client-components>, [">= 0"])
130
+ s.add_dependency(%q<rack-cache>, [">= 0"])
131
+ s.add_dependency(%q<addressable>, [">= 0"])
132
+ s.add_dependency(%q<chunky_png>, [">= 0"])
133
+ s.add_dependency(%q<dimensions>, [">= 0"])
134
+ s.add_dependency(%q<json>, [">= 0"])
135
+ s.add_dependency(%q<rspec>, ["~> 2.7.0"])
136
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
137
+ s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
138
+ end
139
+ else
140
+ s.add_dependency(%q<rake>, [">= 0"])
141
+ s.add_dependency(%q<nokogiri>, [">= 0"])
142
+ s.add_dependency(%q<rest-client>, [">= 0"])
143
+ s.add_dependency(%q<rest-client-components>, [">= 0"])
144
+ s.add_dependency(%q<rack-cache>, [">= 0"])
145
+ s.add_dependency(%q<addressable>, [">= 0"])
146
+ s.add_dependency(%q<chunky_png>, [">= 0"])
147
+ s.add_dependency(%q<dimensions>, [">= 0"])
148
+ s.add_dependency(%q<json>, [">= 0"])
149
+ s.add_dependency(%q<rspec>, ["~> 2.7.0"])
150
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
151
+ s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
152
+ end
153
+ end
154
+
File without changes
@@ -0,0 +1,72 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')
2
+
3
+ describe Shibkit::MetaMeta::Config, "automatic download and refresh settings" do
4
+
5
+ ## Testing a singleton is tricky! Make a copy of the class each time
6
+ before(:each) do
7
+ @config_class = Shibkit::MetaMeta::Config.clone
8
+ @config = @config_class.instance
9
+ end
10
+
11
+ subject { @config }
12
+
13
+ it { should respond_to :autoload= }
14
+ it { should respond_to :autoload? }
15
+ it { should respond_to :auto_refresh= }
16
+ it { should respond_to :auto_refresh? }
17
+
18
+ context "When using default settings" do
19
+
20
+ it "should have autoload set to be active" do
21
+
22
+ @config.autoload?.should == true
23
+
24
+ end
25
+
26
+ it "should have auto_refresh set to active" do
27
+
28
+ @config.auto_refresh?.should == true
29
+
30
+ end
31
+
32
+ end
33
+
34
+ context "When changing settings" do
35
+
36
+ it "should allow autoload setting to be enable or disabled" do
37
+
38
+ @config.autoload=true
39
+ @config.autoload?.should == true
40
+ @config.autoload=false
41
+ @config.autoload?.should == false
42
+
43
+ end
44
+
45
+ it "should allow auto_refresh setting to be enabled or disabled" do
46
+
47
+ @config.auto_refresh=true
48
+ @config.auto_refresh?.should == true
49
+ @config.auto_refresh=false
50
+ @config.auto_refresh?.should == false
51
+
52
+ end
53
+
54
+ it "should only return true or false for #autoload?" do
55
+
56
+ @config.autoload="yup" # Potentially misleading
57
+ @config.autoload?.should == true
58
+ @config.autoload=nil
59
+ @config.autoload?.should == false
60
+
61
+ end
62
+
63
+ it "should only return true or false for #auto_refresh?" do
64
+ @config.auto_refresh="yup" # Potentially misleading
65
+ @config.auto_refresh?.should == true
66
+ @config.auto_refresh=nil
67
+ @config.auto_refresh?.should == false
68
+ end
69
+
70
+ end
71
+
72
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')
2
+
3
+ describe Shibkit::MetaMeta::Config, "class source code quality" do
4
+
5
+ it 'contains no code smells' do
6
+
7
+ source_code = File.expand_path(File.dirname(__FILE__) + '../../../../lib/shibkit/meta_meta/config.rb')
8
+
9
+ source_code.should_not reek
10
+
11
+ end
12
+
13
+ end
@@ -0,0 +1,30 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')
2
+
3
+ describe Shibkit::MetaMeta::Config, "configuration blocks" do
4
+
5
+ ## Testing a singleton is tricky! Make a copy of the class each time
6
+ before(:each) do
7
+ @config_class = Shibkit::MetaMeta::Config.clone
8
+ @config = @config_class.instance
9
+ end
10
+
11
+ subject { @config }
12
+
13
+ it { should respond_to :configure }
14
+
15
+ it "Should allow a configuration block to be used at object creation" do
16
+
17
+ my_config = @config_class.instance { |c| c.smartcache_expiry = 12345 }
18
+ my_config.smartcache_expiry.should == 12345
19
+
20
+ end
21
+
22
+ it "Should allow a configuration block to be used at any time" do
23
+
24
+ my_config = @config_class.instance
25
+ my_config.configure { |c| c.smartcache_expiry = 3333 }
26
+ my_config.smartcache_expiry.should == 3333
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,43 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')
2
+
3
+ describe Shibkit::MetaMeta::Config, "creation and singleton behaviour" do
4
+
5
+ ## Testing a singleton is tricky! Make a copy of the class each time
6
+ before(:each) do
7
+ @config_class = Shibkit::MetaMeta::Config.clone
8
+ end
9
+
10
+ subject { @config_class }
11
+
12
+ it { should respond_to :instance }
13
+
14
+
15
+ it "Should raise an exception if #new is called" do
16
+
17
+ expect { @config_class.new }.should raise_error
18
+
19
+ end
20
+
21
+ context "When first instance is created" do
22
+
23
+ it "should return a Config object" do
24
+
25
+ Shibkit::MetaMeta::Config.instance.class.should == Shibkit::MetaMeta::Config
26
+
27
+ end
28
+
29
+ end
30
+
31
+ context "When an instance is created again" do
32
+
33
+ it "should also be the same object, effectively a singleton" do
34
+
35
+ first = @config_class.instance
36
+ second = @config_class.instance
37
+ first.should == second
38
+
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,216 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')
2
+ require 'rack/cache'
3
+
4
+ describe Shibkit::MetaMeta::Config, "download and file caching settings" do
5
+
6
+ ## Testing a singleton is tricky! Make a copy of the class each time
7
+ before(:each) do
8
+ @config_class = Shibkit::MetaMeta::Config.clone
9
+ @config = @config_class.instance
10
+ end
11
+
12
+ subject { @config }
13
+
14
+ it { should respond_to :download_cache_options= }
15
+ it { should respond_to :download_cache_options }
16
+ it { should respond_to :verbose_downloads= }
17
+ it { should respond_to :verbose_downloads? }
18
+ it { should respond_to :cache_fallback_ttl= }
19
+ it { should respond_to :cache_fallback_ttl }
20
+ it { should respond_to :cache_root= }
21
+ it { should respond_to :cache_root }
22
+
23
+ it "should return a hash of cache options" do
24
+
25
+ @config.download_cache_options.should be_a_kind_of Hash
26
+
27
+ end
28
+
29
+ it "cache options should be compatible with Rack::Cache" do
30
+
31
+ options = @config.download_cache_options
32
+ expect {RestClient.enable Rack::Cache, options}.should_not raise_error
33
+
34
+ end
35
+
36
+ it "should represent download cache data and metadata locations as URLs" do
37
+ options = @config.download_cache_options
38
+ options[:metastore].should match URL_REGEX
39
+ options[:entitystore].should match URL_REGEX
40
+ end
41
+
42
+ context "When using default settings" do
43
+
44
+ describe "the cache options hash" do
45
+
46
+ before(:each) do
47
+ @cache_options = @config.download_cache_options
48
+ end
49
+
50
+ it "should have a two hour default TTL for cached files" do
51
+ @cache_options[:default_ttl].should == 7200
52
+ end
53
+
54
+ it "should store cached metadata inside the cache root in a folder called meta" do
55
+ location = @cache_options[:metastore]
56
+ location.should include @config.cache_root
57
+ location.should include 'meta'
58
+ end
59
+
60
+ it "should store cached data inside the cache root in a folder called body" do
61
+ location = @cache_options[:entitystore]
62
+ location.should include @config.cache_root
63
+ location.should include 'body'
64
+ end
65
+
66
+ it "should have verbose output set to false" do
67
+ @cache_options[:verbose].should be_false
68
+ end
69
+
70
+ end
71
+
72
+ it "should have a fallback ttl of two hours" do
73
+ @config.cache_fallback_ttl.should == 7200
74
+ end
75
+
76
+ it "should have the verbose download setting return false" do
77
+ @config.verbose_downloads?.should be_false
78
+ end
79
+
80
+ context "on Windows" do
81
+
82
+ it "should store cache files in the default TEMP directory" do
83
+
84
+ @config_class.any_instance.stub(:sensible_os?).and_return(false)
85
+ tempbase = 'c:\Temp'
86
+ ENV['TEMP'] = tempbase
87
+
88
+ @config.download_cache_options[:entitystore].should include tempbase.gsub('\\','/')
89
+
90
+ end
91
+
92
+ end
93
+
94
+ context "on sensible operating systems" do
95
+
96
+ it "should store cache files in /tmp/" do
97
+
98
+ @config_class.any_instance.stub(:sensible_os?).and_return(true)
99
+ tempbase = '/tmp'
100
+
101
+ @config.download_cache_options[:entitystore].should include tempbase
102
+
103
+ end
104
+
105
+ end
106
+
107
+ end
108
+
109
+ context "When changing settings" do
110
+
111
+ it "should allow the cache directory to be changed" do
112
+
113
+ @config.cache_root = "/tmp/bananas"
114
+ @config.cache_root.should == "/tmp/bananas"
115
+
116
+ end
117
+
118
+ it "should change the configuration hash when verbose downloads setting is changed" do
119
+
120
+ @config.verbose_downloads?.should be_false
121
+ @config.download_cache_options[:verbose].should be_false
122
+
123
+ @config.verbose_downloads = true
124
+ @config.download_cache_options[:verbose].should be_true
125
+
126
+ end
127
+
128
+ it "should change the default configuration hash when cache root is changed" do
129
+
130
+ @config.cache_root = "/tmp/work"
131
+ @config.download_cache_options[:entitystore].should include "/tmp/work"
132
+ @config.download_cache_options[:metastore].should include "/tmp/work"
133
+
134
+ end
135
+
136
+ context "if an equivalent Rack::Cache setting is configured directing using #download_cache_options" do
137
+
138
+ it "should not change the cache storage settings when #cache_root is changed " do
139
+
140
+ @config.download_cache_options = { :entitystore => 'heap:/' }
141
+ @config.download_cache_options = { :metastore => 'heap:/' }
142
+
143
+ @config.cache_root = "/tmp/scratch"
144
+
145
+ @config.download_cache_options[:entitystore].should == 'heap:/'
146
+ @config.download_cache_options[:metastore ].should == 'heap:/'
147
+
148
+ end
149
+
150
+ it "should always change the configuration hash when #default_ttl is changed" do
151
+
152
+ @config.cache_fallback_ttl = 808
153
+ @config.download_cache_options[:default_ttl].should == 808
154
+
155
+ end
156
+
157
+ it "changing the configuration hash does not change #default_ttl" do
158
+
159
+ @config.download_cache_options = { :default_ttl => 909 }
160
+ @config.cache_fallback_ttl.should_not == 909
161
+
162
+ end
163
+
164
+ it "should always change the configuration hash when #verbose_downloads is changed" do
165
+
166
+ @config.download_cache_options = { :verbose => false }
167
+ @config.verbose_downloads = true
168
+ @config.download_cache_options[:verbose].should == true
169
+
170
+ end
171
+
172
+ it "changing the configuration hash does not change #verbose_downloads" do
173
+
174
+ @config.verbose_downloads = true
175
+ @config.download_cache_options = { :verbose => false }
176
+ @config.verbose_downloads?.should == true
177
+
178
+ end
179
+
180
+ end
181
+
182
+ it "should not allow direct manipulation of the returned config hash" do
183
+
184
+ expect { @config.download_cache_options[:verbose] = true }.should raise_error
185
+
186
+ end
187
+
188
+ it "should allow new options to be merged into the default config hash, overloading those controlled by other methods" do
189
+
190
+ @config.verbose_downloads?.should be_false
191
+ @config.download_cache_options[:verbose].should be_false
192
+
193
+ @config.download_cache_options = { :verbose => true }
194
+ @config.download_cache_options[:verbose].should be_true
195
+ @config.download_cache_options[:default_ttl].should == 7200
196
+
197
+ end
198
+
199
+ it "should allow other, more obscure Rack::Cache options to be set" do
200
+
201
+ @config.download_cache_options[:allow_reload].should be_nil
202
+ @config.download_cache_options[:allow_revalidate].should be_nil
203
+
204
+ @config.download_cache_options = { :allow_reload => true }
205
+ @config.download_cache_options = { :allow_revalidate => true }
206
+
207
+ @config.download_cache_options[:allow_reload].should be_true
208
+ @config.download_cache_options[:allow_revalidate].should be_true
209
+
210
+ end
211
+
212
+ end
213
+
214
+ end
215
+
216
+