apache_secure_download 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/COPYING CHANGED
@@ -1,7 +1,7 @@
1
1
  = License for apache_secure_download
2
-
3
- GNU GENERAL PUBLIC LICENSE
4
- Version 3, 29 June 2007
2
+
3
+ GNU AFFERO GENERAL PUBLIC LICENSE
4
+ Version 3, 19 November 2007
5
5
 
6
6
  Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
7
7
  Everyone is permitted to copy and distribute verbatim copies
@@ -9,17 +9,15 @@
9
9
 
10
10
  Preamble
11
11
 
12
- The GNU General Public License is a free, copyleft license for
13
- software and other kinds of works.
12
+ The GNU Affero General Public License is a free, copyleft license for
13
+ software and other kinds of works, specifically designed to ensure
14
+ cooperation with the community in the case of network server software.
14
15
 
15
16
  The licenses for most software and other practical works are designed
16
17
  to take away your freedom to share and change the works. By contrast,
17
- the GNU General Public License is intended to guarantee your freedom to
18
+ our General Public Licenses are intended to guarantee your freedom to
18
19
  share and change all versions of a program--to make sure it remains free
19
- software for all its users. We, the Free Software Foundation, use the
20
- GNU General Public License for most of our software; it applies also to
21
- any other work released this way by its authors. You can apply it to
22
- your programs, too.
20
+ software for all its users.
23
21
 
24
22
  When we speak of free software, we are referring to freedom, not
25
23
  price. Our General Public Licenses are designed to make sure that you
@@ -28,44 +26,34 @@
28
26
  want it, that you can change the software or use pieces of it in new
29
27
  free programs, and that you know you can do these things.
30
28
 
31
- To protect your rights, we need to prevent others from denying you
32
- these rights or asking you to surrender the rights. Therefore, you have
33
- certain responsibilities if you distribute copies of the software, or if
34
- you modify it: responsibilities to respect the freedom of others.
35
-
36
- For example, if you distribute copies of such a program, whether
37
- gratis or for a fee, you must pass on to the recipients the same
38
- freedoms that you received. You must make sure that they, too, receive
39
- or can get the source code. And you must show them these terms so they
40
- know their rights.
41
-
42
- Developers that use the GNU GPL protect your rights with two steps:
43
- (1) assert copyright on the software, and (2) offer you this License
44
- giving you legal permission to copy, distribute and/or modify it.
45
-
46
- For the developers' and authors' protection, the GPL clearly explains
47
- that there is no warranty for this free software. For both users' and
48
- authors' sake, the GPL requires that modified versions be marked as
49
- changed, so that their problems will not be attributed erroneously to
50
- authors of previous versions.
51
-
52
- Some devices are designed to deny users access to install or run
53
- modified versions of the software inside them, although the manufacturer
54
- can do so. This is fundamentally incompatible with the aim of
55
- protecting users' freedom to change the software. The systematic
56
- pattern of such abuse occurs in the area of products for individuals to
57
- use, which is precisely where it is most unacceptable. Therefore, we
58
- have designed this version of the GPL to prohibit the practice for those
59
- products. If such problems arise substantially in other domains, we
60
- stand ready to extend this provision to those domains in future versions
61
- of the GPL, as needed to protect the freedom of users.
62
-
63
- Finally, every program is threatened constantly by software patents.
64
- States should not allow patents to restrict development and use of
65
- software on general-purpose computers, but in those that do, we wish to
66
- avoid the special danger that patents applied to a free program could
67
- make it effectively proprietary. To prevent this, the GPL assures that
68
- patents cannot be used to render the program non-free.
29
+ Developers that use our General Public Licenses protect your rights
30
+ with two steps: (1) assert copyright on the software, and (2) offer
31
+ you this License which gives you legal permission to copy, distribute
32
+ and/or modify the software.
33
+
34
+ A secondary benefit of defending all users' freedom is that
35
+ improvements made in alternate versions of the program, if they
36
+ receive widespread use, become available for other developers to
37
+ incorporate. Many developers of free software are heartened and
38
+ encouraged by the resulting cooperation. However, in the case of
39
+ software used on network servers, this result may fail to come about.
40
+ The GNU General Public License permits making a modified version and
41
+ letting the public access it on a server without ever releasing its
42
+ source code to the public.
43
+
44
+ The GNU Affero General Public License is designed specifically to
45
+ ensure that, in such cases, the modified source code becomes available
46
+ to the community. It requires the operator of a network server to
47
+ provide the source code of the modified version running there to the
48
+ users of that server. Therefore, public use of a modified version, on
49
+ a publicly accessible server, gives the public access to the source
50
+ code of the modified version.
51
+
52
+ An older license, called the Affero General Public License and
53
+ published by Affero, was designed to accomplish similar goals. This is
54
+ a different license, not a version of the Affero GPL, but Affero has
55
+ released a new version of the Affero GPL which permits relicensing under
56
+ this license.
69
57
 
70
58
  The precise terms and conditions for copying, distribution and
71
59
  modification follow.
@@ -74,7 +62,7 @@
74
62
 
75
63
  0. Definitions.
76
64
 
77
- "This License" refers to version 3 of the GNU General Public License.
65
+ "This License" refers to version 3 of the GNU Affero General Public License.
78
66
 
79
67
  "Copyright" also means copyright-like laws that apply to other kinds of
80
68
  works, such as semiconductor masks.
@@ -551,35 +539,45 @@
551
539
  the Program, the only way you could satisfy both those terms and this
552
540
  License would be to refrain entirely from conveying the Program.
553
541
 
554
- 13. Use with the GNU Affero General Public License.
542
+ 13. Remote Network Interaction; Use with the GNU General Public License.
543
+
544
+ Notwithstanding any other provision of this License, if you modify the
545
+ Program, your modified version must prominently offer all users
546
+ interacting with it remotely through a computer network (if your version
547
+ supports such interaction) an opportunity to receive the Corresponding
548
+ Source of your version by providing access to the Corresponding Source
549
+ from a network server at no charge, through some standard or customary
550
+ means of facilitating copying of software. This Corresponding Source
551
+ shall include the Corresponding Source for any work covered by version 3
552
+ of the GNU General Public License that is incorporated pursuant to the
553
+ following paragraph.
555
554
 
556
555
  Notwithstanding any other provision of this License, you have
557
556
  permission to link or combine any covered work with a work licensed
558
- under version 3 of the GNU Affero General Public License into a single
557
+ under version 3 of the GNU General Public License into a single
559
558
  combined work, and to convey the resulting work. The terms of this
560
559
  License will continue to apply to the part which is the covered work,
561
- but the special requirements of the GNU Affero General Public License,
562
- section 13, concerning interaction through a network will apply to the
563
- combination as such.
560
+ but the work with which it is combined will remain governed by version
561
+ 3 of the GNU General Public License.
564
562
 
565
563
  14. Revised Versions of this License.
566
564
 
567
565
  The Free Software Foundation may publish revised and/or new versions of
568
- the GNU General Public License from time to time. Such new versions will
569
- be similar in spirit to the present version, but may differ in detail to
566
+ the GNU Affero General Public License from time to time. Such new versions
567
+ will be similar in spirit to the present version, but may differ in detail to
570
568
  address new problems or concerns.
571
569
 
572
570
  Each version is given a distinguishing version number. If the
573
- Program specifies that a certain numbered version of the GNU General
571
+ Program specifies that a certain numbered version of the GNU Affero General
574
572
  Public License "or any later version" applies to it, you have the
575
573
  option of following the terms and conditions either of that numbered
576
574
  version or of any later version published by the Free Software
577
575
  Foundation. If the Program does not specify a version number of the
578
- GNU General Public License, you may choose any version ever published
576
+ GNU Affero General Public License, you may choose any version ever published
579
577
  by the Free Software Foundation.
580
578
 
581
579
  If the Program specifies that a proxy can decide which future
582
- versions of the GNU General Public License can be used, that proxy's
580
+ versions of the GNU Affero General Public License can be used, that proxy's
583
581
  public statement of acceptance of a version permanently authorizes you
584
582
  to choose that version for the Program.
585
583
 
@@ -637,40 +635,29 @@
637
635
  Copyright (C) <year> <name of author>
638
636
 
639
637
  This program is free software: you can redistribute it and/or modify
640
- it under the terms of the GNU General Public License as published by
638
+ it under the terms of the GNU Affero General Public License as published by
641
639
  the Free Software Foundation, either version 3 of the License, or
642
640
  (at your option) any later version.
643
641
 
644
642
  This program is distributed in the hope that it will be useful,
645
643
  but WITHOUT ANY WARRANTY; without even the implied warranty of
646
644
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
647
- GNU General Public License for more details.
645
+ GNU Affero General Public License for more details.
648
646
 
649
- You should have received a copy of the GNU General Public License
647
+ You should have received a copy of the GNU Affero General Public License
650
648
  along with this program. If not, see <http://www.gnu.org/licenses/>.
651
649
 
652
650
  Also add information on how to contact you by electronic and paper mail.
653
651
 
654
- If the program does terminal interaction, make it output a short
655
- notice like this when it starts in an interactive mode:
656
-
657
- <program> Copyright (C) <year> <name of author>
658
- This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
659
- This is free software, and you are welcome to redistribute it
660
- under certain conditions; type `show c' for details.
661
-
662
- The hypothetical commands `show w' and `show c' should show the appropriate
663
- parts of the General Public License. Of course, your program's commands
664
- might be different; for a GUI interface, you would use an "about box".
652
+ If your software can interact with users remotely through a computer
653
+ network, you should also make sure that it provides a way for users to
654
+ get its source. For example, if your program is a web application, its
655
+ interface could display a "Source" link that leads users to an archive
656
+ of the code. There are many ways you could offer source, and different
657
+ solutions will be better for different programs; see section 13 for the
658
+ specific requirements.
665
659
 
666
660
  You should also get your employer (if you work as a programmer) or school,
667
661
  if any, to sign a "copyright disclaimer" for the program, if necessary.
668
- For more information on this, and how to apply and follow the GNU GPL, see
662
+ For more information on this, and how to apply and follow the GNU AGPL, see
669
663
  <http://www.gnu.org/licenses/>.
670
-
671
- The GNU General Public License does not permit incorporating your program
672
- into proprietary programs. If your program is a subroutine library, you
673
- may consider it more useful to permit linking proprietary applications with
674
- the library. If this is what you want to do, use the GNU Lesser General
675
- Public License instead of this License. But first, please read
676
- <http://www.gnu.org/philosophy/why-not-lgpl.html>.
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to apache_secure_download version 0.1.0
5
+ This documentation refers to apache_secure_download version 0.1.1
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -48,10 +48,9 @@ See Apache::SecureDownload::Util.secure_url for more examples.
48
48
  == LINKS
49
49
 
50
50
  <b></b>
51
- Documentation:: <http://prometheus.rubyforge.org/apache_secure_download>
52
- Source code (old):: <http://prometheus.rubyforge.org/svn/scratch/apache_secure_download>
53
- Source code:: <http://github.com/blackwinter/apache_secure_download>
54
- Rubyforge project:: <http://rubyforge.org/projects/prometheus>
51
+ Documentation:: http://prometheus.rubyforge.org/apache_secure_download
52
+ Source code:: http://github.com/blackwinter/apache_secure_download
53
+ RubyForge project:: http://rubyforge.org/projects/prometheus
55
54
 
56
55
 
57
56
  == AUTHORS
@@ -61,18 +60,18 @@ Rubyforge project:: <http://rubyforge.org/projects/prometheus>
61
60
 
62
61
  == LICENSE AND COPYRIGHT
63
62
 
64
- Copyright (C) 2008-2010 University of Cologne,
63
+ Copyright (C) 2008-2011 University of Cologne,
65
64
  Albertus-Magnus-Platz, 50923 Cologne, Germany
66
65
 
67
66
  apache_secure_download is free software: you can redistribute it and/or modify
68
- it under the terms of the GNU General Public License as published by the Free
69
- Software Foundation, either version 3 of the License, or (at your option) any
70
- later version.
67
+ it under the terms of the GNU Affero General Public License as published by
68
+ the Free Software Foundation, either version 3 of the License, or (at your
69
+ option) any later version.
71
70
 
72
71
  apache_secure_download is distributed in the hope that it will be useful, but
73
72
  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
74
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
75
- details.
73
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
74
+ for more details.
76
75
 
77
- You should have received a copy of the GNU General Public License along
76
+ You should have received a copy of the GNU Affero General Public License along
78
77
  with apache_secure_download. If not, see <http://www.gnu.org/licenses/>.
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- require %q{lib/apache/secure_download/version}
1
+ require File.expand_path(%q{../lib/apache/secure_download/version}, __FILE__)
2
2
 
3
3
  begin
4
4
  require 'hen'
@@ -10,15 +10,19 @@ begin
10
10
  },
11
11
 
12
12
  :gem => {
13
- :version => Apache::SecureDownload::VERSION,
14
- :summary => %q{Apache module providing secure downloading functionality, just like Mongrel Secure Download does for mongrel.},
15
- :files => FileList['lib/**/*.rb'].to_a,
16
- :extra_files => FileList['[A-Z]*'].to_a,
17
- :dependencies => %w[]
13
+ :version => Apache::SecureDownload::VERSION,
14
+ :summary => %q{Apache module providing secure downloading functionality, just like Mongrel Secure Download does for mongrel.},
15
+ :author => %q{Jens Wille},
16
+ :email => %q{jens.wille@uni-koeln.de}
18
17
  }
19
18
  }}
20
- rescue LoadError
21
- abort "Please install the 'hen' gem first."
19
+ rescue LoadError => err
20
+ warn "Please install the `hen' gem. (#{err})"
22
21
  end
23
22
 
24
- ### Place your custom Rake tasks here.
23
+ desc "Run benchmarks"
24
+ task :bench do
25
+ Dir["#{File.dirname(__FILE__)}/bench/**/*_bench.rb"].each { |bench|
26
+ load bench, true
27
+ }
28
+ end
@@ -3,7 +3,7 @@
3
3
  # #
4
4
  # A component of apache_secure_download. #
5
5
  # #
6
- # Copyright (C) 2008-2010 University of Cologne, #
6
+ # Copyright (C) 2008-2011 University of Cologne, #
7
7
  # Albertus-Magnus-Platz, #
8
8
  # 50923 Cologne, Germany #
9
9
  # #
@@ -11,17 +11,18 @@
11
11
  # Jens Wille <jens.wille@uni-koeln.de> #
12
12
  # #
13
13
  # apache_secure_download is free software: you can redistribute it and/or #
14
- # modify it under the terms of the GNU General Public License as published by #
15
- # the Free Software Foundation, either version 3 of the License, or (at your #
16
- # option) any later version. #
14
+ # modify it under the terms of the GNU Affero General Public License as #
15
+ # published by the Free Software Foundation, either version 3 of the #
16
+ # License, or (at your option) any later version. #
17
17
  # #
18
- # apache_secure_download is distributed in the hope that it will be useful, #
19
- # but WITHOUT ANY WARRANTY; without even the implied warranty of #
20
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General #
21
- # Public License for more details. #
18
+ # apache_secure_download is distributed in the hope that it will be #
19
+ # useful, but WITHOUT ANY WARRANTY; without even the implied warranty #
20
+ # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
21
+ # Affero General Public License for more details. #
22
22
  # #
23
- # You should have received a copy of the GNU General Public License along #
24
- # with apache_secure_download. If not, see <http://www.gnu.org/licenses/>. #
23
+ # You should have received a copy of the GNU Affero General Public #
24
+ # License along with apache_secure_download. If not, see #
25
+ # <http://www.gnu.org/licenses/>. #
25
26
  # #
26
27
  ###############################################################################
27
28
  #++
@@ -6,7 +6,7 @@ module Apache
6
6
 
7
7
  MAJOR = 0
8
8
  MINOR = 1
9
- TINY = 0
9
+ TINY = 1
10
10
 
11
11
  class << self
12
12
 
@@ -12,17 +12,18 @@
12
12
  # Jens Wille <jens.wille@uni-koeln.de> #
13
13
  # #
14
14
  # apache_secure_download is free software: you can redistribute it and/or #
15
- # modify it under the terms of the GNU General Public License as published by #
16
- # the Free Software Foundation, either version 3 of the License, or (at your #
17
- # option) any later version. #
15
+ # modify it under the terms of the GNU Affero General Public License as #
16
+ # published by the Free Software Foundation, either version 3 of the #
17
+ # License, or (at your option) any later version. #
18
18
  # #
19
- # apache_secure_download is distributed in the hope that it will be useful, #
20
- # but WITHOUT ANY WARRANTY; without even the implied warranty of #
21
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General #
22
- # Public License for more details. #
19
+ # apache_secure_download is distributed in the hope that it will be #
20
+ # useful, but WITHOUT ANY WARRANTY; without even the implied warranty #
21
+ # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
22
+ # Affero General Public License for more details. #
23
23
  # #
24
- # You should have received a copy of the GNU General Public License along #
25
- # with apache_secure_download. If not, see <http://www.gnu.org/licenses/>. #
24
+ # You should have received a copy of the GNU Affero General Public #
25
+ # License along with apache_secure_download. If not, see #
26
+ # <http://www.gnu.org/licenses/>. #
26
27
  # #
27
28
  ###############################################################################
28
29
  #++
@@ -0,0 +1,392 @@
1
+ describe Apache::SecureDownload::Util do
2
+
3
+ before :each do
4
+ @module = Apache::SecureDownload::Util
5
+ @secret = 'secret'
6
+ end
7
+
8
+ describe "#secure_url" do
9
+
10
+ before :each do
11
+ @url = '/secure/url'
12
+ @now = Time.at(1204024618)
13
+ end
14
+
15
+ describe "generating secure URLs" do
16
+
17
+ before :each do
18
+ @timestamp = @now.to_i + 60
19
+ @token = '5671a9b3966e8bbed91fc0bb5594d576c504cdf0'
20
+
21
+ @result = "?timestamp=#{@timestamp}&token=#{@token}"
22
+ end
23
+
24
+ it "should generate secure URL" do
25
+ url = @url
26
+ @module.secure_url(@secret, url).should == url + @result
27
+ end
28
+
29
+ it "should take path component into account" do
30
+ url = @url + '2'
31
+ @module.secure_url(@secret, url).should =~ /\A#{Regexp.escape(url)}\?/
32
+ @module.secure_url(@secret, url).should_not == url + @result
33
+ end
34
+
35
+ it "should ignore host component" do
36
+ url = 'http://example.com' + @url
37
+ @module.secure_url(@secret, url).should == url + @result
38
+ end
39
+
40
+ it "should preserve query component" do
41
+ url = @url + '?a=b&x=y'
42
+ @module.secure_url(@secret, url).should =~ /\A#{Regexp.escape(url)}&/
43
+ end
44
+
45
+ it "should preserve URL fragment" do
46
+ url = @url + '#foo'
47
+ result = @module.secure_url(@secret, url)
48
+
49
+ result.should =~ /\A#{Regexp.escape(@url)}\?/
50
+ result.should =~ /#foo\z/
51
+ end
52
+
53
+ it "should preserve query component and URL fragment" do
54
+ url = @url + '?x=y#foo'
55
+ result = @module.secure_url(@secret, url)
56
+
57
+ result.should =~ /\A#{Regexp.escape(@url)}\?x=y&/
58
+ result.should =~ /#foo\z/
59
+ end
60
+
61
+ it "should respect secret" do
62
+ @module.secure_url(@secret.swapcase, @url).should_not == @url + @result
63
+ end
64
+
65
+ end
66
+
67
+ describe "with custom expiration" do
68
+
69
+ before :each do
70
+ @result1 = "#{@url}?timestamp=1204025218&token=7e51f91cf4406f308a8df24f4e2cbf188de3c1bf"
71
+ @result2 = "#{@url}?timestamp=1204026000&token=58eb12f9fc3fcd984fe4e918d3fd0590392c172d"
72
+ end
73
+
74
+ it "should accept time" do
75
+ @module.secure_url(@secret, @url, Time.now + 600).should == @result1
76
+ end
77
+
78
+ it "should accept offset" do
79
+ @module.secure_url(@secret, @url, :offset => 600).should == @result2
80
+ @result2.should_not == @result1
81
+ end
82
+
83
+ it "should disable caching with offset" do
84
+ @module.secure_url(@secret, @url, :offset => 600, :cache => false).should == @result1
85
+ @result1.should_not == @result2
86
+ end
87
+
88
+ end
89
+
90
+ describe "caching" do
91
+
92
+ before :each do
93
+ @result1 = "#{@url}?timestamp=1204024680&token=ccf279daf1787d34ad063cbf5851ee88aae967fb"
94
+ @result2 = "#{@url}?timestamp=1204024740&token=c7dcea5679ad539a7bad1dc4b7f44eb3dd36d6e8"
95
+ @result3 = "#{@url}?timestamp=1204024800&token=aa11618f1cc0883a29e9239b777ca53dfc4d9604"
96
+ end
97
+
98
+ describe "explicitly (with expires)" do
99
+
100
+ it "should produce identical URLs for a window of 1 minute (on average)" do
101
+ t = Time.now
102
+
103
+ @module.secure_url(@secret, @url, :expires => t, :cache => 60).should == @result1
104
+ @module.secure_url(@secret, @url, :expires => t + 30, :cache => 60).should == @result1
105
+ @module.secure_url(@secret, @url, :expires => t + 60, :cache => 60).should == @result2
106
+ @module.secure_url(@secret, @url, :expires => t + 90, :cache => 60).should == @result2
107
+ end
108
+
109
+ end
110
+
111
+ describe "implicitly (with offset)" do
112
+
113
+ it "should produce identical URLs for a window of 1 minute (on average)" do
114
+ @module.secure_url(@secret, @url, :offset => 60).should == @result2
115
+ @now += 30 # 30 seconds later...
116
+ @module.secure_url(@secret, @url, :offset => 60).should == @result2
117
+ @now += 30 # 30 seconds later...
118
+ @module.secure_url(@secret, @url, :offset => 60).should == @result3
119
+ @now += 30 # 30 seconds later...
120
+ @module.secure_url(@secret, @url, :offset => 60).should == @result3
121
+ end
122
+
123
+ end
124
+
125
+ end
126
+
127
+ end
128
+
129
+ describe "#token" do
130
+
131
+ before :each do
132
+ @path = '/some/path'
133
+ @timestamp = Time.now.to_i
134
+
135
+ @result = @module.token(@secret, @path, @timestamp)
136
+ end
137
+
138
+ it "should take secret into account" do
139
+ @module.token(@secret.swapcase, @path, @timestamp).should_not == @result
140
+ end
141
+
142
+ it "should take path into account" do
143
+ @module.token(@secret, @path + '/foo', @timestamp).should_not == @result
144
+ end
145
+
146
+ it "should take query parameters in path into account" do
147
+ @module.token(@secret, @path + '?foo=bar', @timestamp).should_not == @result
148
+ end
149
+
150
+ it "should take timestamp into account" do
151
+ @module.token(@secret, @path, @timestamp + 42).should_not == @result
152
+ end
153
+
154
+ it "should ignore timestamp parameter in path" do
155
+ @module.token(@secret, @path + '?timestamp=foo', @timestamp).should == @result
156
+ end
157
+
158
+ it "should ignore token parameter in path" do
159
+ @module.token(@secret, @path + '?token=bar', @timestamp).should == @result
160
+ end
161
+
162
+ it "should ignore timestamp and token parameters in path" do
163
+ @module.token(@secret, @path + '?timestamp=foo&token=bar', @timestamp).should == @result
164
+ end
165
+
166
+ it "should ignore timestamp and token parameters in path, regardless of order" do
167
+ @module.token(@secret, @path + '?token=bar&timestamp=foo', @timestamp).should == @result
168
+ end
169
+
170
+ describe "when other parameters are present in path" do
171
+
172
+ describe "at the front" do
173
+
174
+ before :each do
175
+ @path2 = @path + '?foo=bar'
176
+ @result2 = @module.token(@secret, @path2, @timestamp)
177
+ end
178
+
179
+ it "should not ignore them" do
180
+ @module.token(@secret, @path2 + '&timestamp=foo&token=bar', @timestamp).should_not == @result
181
+ end
182
+
183
+ it "should ignore timestamp parameter in path" do
184
+ @module.token(@secret, @path2 + '&timestamp=foo', @timestamp).should == @result2
185
+ end
186
+
187
+ it "should ignore token parameter in path" do
188
+ @module.token(@secret, @path2 + '&token=bar', @timestamp).should == @result2
189
+ end
190
+
191
+ it "should ignore timestamp and token parameters in path" do
192
+ @module.token(@secret, @path2 + '&timestamp=foo&token=bar', @timestamp).should == @result2
193
+ end
194
+
195
+ it "should ignore timestamp and token parameters in path, regardless of order" do
196
+ @module.token(@secret, @path2 + '&token=bar&timestamp=foo', @timestamp).should == @result2
197
+ end
198
+
199
+ end
200
+
201
+ describe "at the end" do
202
+
203
+ before :each do
204
+ @query = '&foo=bar'
205
+ @result2 = @module.token(@secret, @path + @query.sub(/&/, '?'), @timestamp)
206
+ end
207
+
208
+ it "should not ignore them" do
209
+ @module.token(@secret, @path + '?timestamp=foo&token=bar' + @query, @timestamp).should_not == @result
210
+ end
211
+
212
+ it "should ignore timestamp parameter in path" do
213
+ @module.token(@secret, @path + '?timestamp=foo' + @query, @timestamp).should == @result2
214
+ end
215
+
216
+ it "should ignore token parameter in path" do
217
+ @module.token(@secret, @path + '?token=bar' + @query, @timestamp).should == @result2
218
+ end
219
+
220
+ it "should ignore timestamp and token parameters in path" do
221
+ @module.token(@secret, @path + '?timestamp=foo&token=bar' + @query, @timestamp).should == @result2
222
+ end
223
+
224
+ it "should ignore timestamp and token parameters in path, regardless of order" do
225
+ @module.token(@secret, @path + '?token=bar&timestamp=foo' + @query, @timestamp).should == @result2
226
+ end
227
+
228
+ end
229
+
230
+ end
231
+
232
+ end
233
+
234
+ describe "#real_path" do
235
+
236
+ before :each do
237
+ @path = '/some/path'
238
+ end
239
+
240
+ describe "without recognized query parameters" do
241
+
242
+ it "should leave the path intact" do
243
+ @module.real_path(@path).should == @path
244
+ end
245
+
246
+ it "should leave other query parameters intact" do
247
+ @module.real_path(@path + '?foo=bar').should == @path + '?foo=bar'
248
+ end
249
+
250
+ end
251
+
252
+ describe "with recognized query parameters" do
253
+
254
+ it "should remove timestamp parameter" do
255
+ @module.real_path(@path + '?timestamp=foo').should == @path
256
+ end
257
+
258
+ it "should remove token parameter" do
259
+ @module.real_path(@path + '?token=bar').should == @path
260
+ end
261
+
262
+ it "should remove timestamp and token parameters" do
263
+ @module.real_path(@path + '?timestamp=foo&token=bar').should == @path
264
+ end
265
+
266
+ it "should remove timestamp and token parameters, regardless of order" do
267
+ @module.real_path(@path + '?token=bar&timestamp=foo').should == @path
268
+ end
269
+
270
+ describe "when other parameters are present" do
271
+
272
+ describe "at the front" do
273
+
274
+ before :each do
275
+ @path2 = @path + '?foo=bar'
276
+ end
277
+
278
+ it "should remove timestamp parameter" do
279
+ @module.real_path(@path2 + '&timestamp=foo').should == @path2
280
+ end
281
+
282
+ it "should remove token parameter" do
283
+ @module.real_path(@path2 + '&token=bar').should == @path2
284
+ end
285
+
286
+ it "should remove timestamp and token parameters" do
287
+ @module.real_path(@path2 + '&timestamp=foo&token=bar').should == @path2
288
+ end
289
+
290
+ it "should remove timestamp and token parameters, regardless of order" do
291
+ @module.real_path(@path2 + '&token=bar&timestamp=foo').should == @path2
292
+ end
293
+
294
+ end
295
+
296
+ describe "at the end" do
297
+
298
+ before :each do
299
+ @query = '&foo=bar'
300
+ @path2 = @path + @query.sub(/&/, '?')
301
+ end
302
+
303
+ it "should remove timestamp parameter" do
304
+ @module.real_path(@path + '?timestamp=foo' + @query).should == @path2
305
+ end
306
+
307
+ it "should remove token parameter" do
308
+ @module.real_path(@path + '?token=bar' + @query).should == @path2
309
+ end
310
+
311
+ it "should remove timestamp and token parameters" do
312
+ @module.real_path(@path + '?timestamp=foo&token=bar' + @query).should == @path2
313
+ end
314
+
315
+ it "should remove timestamp and token parameters, regardless of order" do
316
+ @module.real_path(@path + '?token=bar&timestamp=foo' + @query).should == @path2
317
+ end
318
+
319
+ end
320
+
321
+ end
322
+
323
+ end
324
+
325
+ end
326
+
327
+ describe "#real_query" do
328
+
329
+ before :each do
330
+ @query = 'some=query'
331
+ end
332
+
333
+ describe "without recognized query parameters" do
334
+
335
+ it "should leave the query intact" do
336
+ @module.real_query(@query).should == @query
337
+ end
338
+
339
+ it "should leave other query parameters intact" do
340
+ @module.real_query(@query + '&foo=bar').should == @query + '&foo=bar'
341
+ end
342
+
343
+ end
344
+
345
+ describe "with recognized query parameters" do
346
+
347
+ it "should remove timestamp parameter" do
348
+ @module.real_query(@query + '&timestamp=foo').should == @query
349
+ end
350
+
351
+ it "should remove token parameter" do
352
+ @module.real_query(@query + '&token=bar').should == @query
353
+ end
354
+
355
+ it "should remove timestamp and token parameters" do
356
+ @module.real_query(@query + '&timestamp=foo&token=bar').should == @query
357
+ end
358
+
359
+ it "should remove timestamp and token parameters, regardless of order" do
360
+ @module.real_query(@query + '&token=bar&timestamp=foo').should == @query
361
+ end
362
+
363
+ describe "when other parameters are present" do
364
+
365
+ before :each do
366
+ @params = '&foo=bar'
367
+ @query2 = @query + @params
368
+ end
369
+
370
+ it "should remove timestamp parameter" do
371
+ @module.real_query(@query + '&timestamp=foo' + @params).should == @query2
372
+ end
373
+
374
+ it "should remove token parameter" do
375
+ @module.real_query(@query + '&token=bar' + @params).should == @query2
376
+ end
377
+
378
+ it "should remove timestamp and token parameters" do
379
+ @module.real_query(@query + '&timestamp=foo&token=bar' + @params).should == @query2
380
+ end
381
+
382
+ it "should remove timestamp and token parameters, regardless of order" do
383
+ @module.real_query(@query + '&token=bar&timestamp=foo' + @params).should == @query2
384
+ end
385
+
386
+ end
387
+
388
+ end
389
+
390
+ end
391
+
392
+ end
@@ -0,0 +1,257 @@
1
+ describe Apache::SecureDownload do
2
+
3
+ before :each do
4
+ @class = Apache::SecureDownload
5
+ end
6
+
7
+ describe "#initialize" do
8
+
9
+ it "should require a secret" do
10
+ lambda { @class.new(nil) }.should raise_error(ArgumentError, 'secret is missing')
11
+ end
12
+
13
+ it "should accept a string for secret" do
14
+ @class.new('secret').should be_an_instance_of(@class)
15
+ end
16
+
17
+ it "should require secret to be a string" do
18
+ lambda { @class.new(42) }.should raise_error(ArgumentError, 'secret is missing')
19
+ end
20
+
21
+ it "should not require :deny" do
22
+ @class.new('secret', :deny => nil).should be_an_instance_of(@class)
23
+ end
24
+
25
+ it "should accept a regexp for :deny" do
26
+ @class.new('secret', :deny => /regexp/).should be_an_instance_of(@class)
27
+ end
28
+
29
+ it "should require :deny to be a regexp" do
30
+ lambda { @class.new('secret', :deny => 'regexp') }.should raise_error(ArgumentError, ':deny is not a regexp')
31
+ end
32
+
33
+ it "should not require :allow" do
34
+ @class.new('secret', :allow => nil).should be_an_instance_of(@class)
35
+ end
36
+
37
+ it "should accept a regexp for :allow" do
38
+ @class.new('secret', :allow => /regexp/).should be_an_instance_of(@class)
39
+ end
40
+
41
+ it "should require :allow to be a regexp" do
42
+ lambda { @class.new('secret', :allow => 'regexp') }.should raise_error(ArgumentError, ':allow is not a regexp')
43
+ end
44
+
45
+ it "should accept :deny and :allow at the same time" do
46
+ @class.new('secret', :deny => /regexp/, :allow => /regexp/).should be_an_instance_of(@class)
47
+ end
48
+
49
+ end
50
+
51
+ describe "#check_access" do
52
+
53
+ def self.it_should_be_allowed(msg, &block)
54
+ it "should be allowed #{msg}" do
55
+ instance_eval(&block) if block
56
+
57
+ mock_request
58
+ @handler.check_access(@request).should == Apache::OK
59
+ end
60
+ end
61
+
62
+ def self.it_should_be_forbidden(msg, &block)
63
+ it "should be forbidden #{msg}" do
64
+ instance_eval(&block) if block
65
+
66
+ mock_request
67
+ @handler.check_access(@request).should == Apache::FORBIDDEN
68
+ end
69
+ end
70
+
71
+ before :each do
72
+ @secret = 'secret'
73
+ @uri = '/some/uri'
74
+
75
+ @timestamp = Time.now.to_i + 23
76
+ @token = @class::Util.token(@secret, @uri, @timestamp)
77
+
78
+ @handler = @class.new(@secret)
79
+ end
80
+
81
+ describe "normally", :shared => true do
82
+
83
+ it_should_be_allowed "with correct secret"
84
+
85
+ it_should_be_forbidden "with incorrect secret" do
86
+ @token = @class::Util.token(@secret.swapcase, @uri, @timestamp)
87
+ end
88
+
89
+ it_should_be_forbidden "for different URL" do
90
+ @token = @class::Util.token(@secret, @uri + '2', @timestamp)
91
+ end
92
+
93
+ it_should_be_forbidden "with different timestamp" do
94
+ @token = @class::Util.token(@secret, @uri, @timestamp + 42)
95
+ end
96
+
97
+ it_should_be_forbidden "when expired" do
98
+ @now += 60
99
+ end
100
+
101
+ end
102
+
103
+ describe "always allowed", :shared => true do
104
+
105
+ it_should_be_allowed "with correct secret"
106
+
107
+ it_should_be_allowed "with incorrect secret" do
108
+ @token = @class::Util.token(@secret.swapcase, @uri, @timestamp)
109
+ end
110
+
111
+ it_should_be_allowed "for different URL" do
112
+ @token = @class::Util.token(@secret, @uri + '2', @timestamp)
113
+ end
114
+
115
+ it_should_be_allowed "with different timestamp" do
116
+ @token = @class::Util.token(@secret, @uri, @timestamp + 42)
117
+ end
118
+
119
+ it_should_be_allowed "when expired" do
120
+ @now += 60
121
+ end
122
+
123
+ end
124
+
125
+ describe "always forbidden", :shared => true do
126
+
127
+ it_should_be_forbidden "with correct secret"
128
+
129
+ it_should_be_forbidden "with incorrect secret" do
130
+ @token = @class::Util.token(@secret.swapcase, @uri, @timestamp)
131
+ end
132
+
133
+ it_should_be_forbidden "for different URL" do
134
+ @token = @class::Util.token(@secret, @uri + '2', @timestamp)
135
+ end
136
+
137
+ it_should_be_forbidden "with different timestamp" do
138
+ @token = @class::Util.token(@secret, @uri, @timestamp + 42)
139
+ end
140
+
141
+ it_should_be_forbidden "when expired" do
142
+ @now += 60
143
+ end
144
+
145
+ end
146
+
147
+ it_should_behave_like "normally"
148
+
149
+ describe "with query args" do
150
+
151
+ before :each do
152
+ @args = 'foo=bar'
153
+ @token = @class::Util.token(@secret, "#{@uri}?#{@args}", @timestamp)
154
+ end
155
+
156
+ it_should_behave_like "normally"
157
+
158
+ end
159
+
160
+ describe "with matching :allow" do
161
+
162
+ before :each do
163
+ @handler = @class.new(@secret, :allow => /\A\/some\//)
164
+ end
165
+
166
+ it_should_behave_like "always allowed"
167
+
168
+ describe "and matching :deny" do
169
+
170
+ before :each do
171
+ @handler.instance_variable_set(:@deny, /\A\/some\//)
172
+ end
173
+
174
+ it_should_behave_like "always forbidden"
175
+
176
+ end
177
+
178
+ describe "and non-matching :deny" do
179
+
180
+ before :each do
181
+ @handler.instance_variable_set(:@deny, /\A\/other\//)
182
+ end
183
+
184
+ it_should_behave_like "always allowed"
185
+
186
+ end
187
+
188
+ end
189
+
190
+ describe "with non-matching :allow" do
191
+
192
+ before :each do
193
+ @handler = @class.new(@secret, :allow => /\A\/other\//)
194
+ end
195
+
196
+ it_should_behave_like "normally"
197
+
198
+ end
199
+
200
+ describe "with matching :deny" do
201
+
202
+ before :each do
203
+ @handler = @class.new(@secret, :deny => /\A\/some\//)
204
+ end
205
+
206
+ it_should_behave_like "always forbidden"
207
+
208
+ describe "and matching :allow" do
209
+
210
+ before :each do
211
+ @handler.instance_variable_set(:@allow, /\A\/some\//)
212
+ end
213
+
214
+ it_should_behave_like "always forbidden"
215
+
216
+ end
217
+
218
+ describe "and non-matching :allow" do
219
+
220
+ before :each do
221
+ @handler.instance_variable_set(:@allow, /\A\/other\//)
222
+ end
223
+
224
+ it_should_behave_like "always forbidden"
225
+
226
+ end
227
+
228
+ end
229
+
230
+ describe "with non-matching :deny" do
231
+
232
+ before :each do
233
+ @handler = @class.new(@secret, :deny => /\A\/other\//)
234
+ end
235
+
236
+ it_should_behave_like "normally"
237
+
238
+ end
239
+
240
+ def mock_request
241
+ args = "timestamp=#{@timestamp}&token=#{@token}"
242
+ args = "#{@args}&#{args}" if @args
243
+
244
+ clean_args = @class::Util.real_query(args)
245
+
246
+ @request = mock('Request', :uri => @uri, :unparsed_uri => "#{@uri}?#{args}")
247
+
248
+ @request.should_receive(:param).with('timestamp').once.and_return(@timestamp)
249
+ @request.should_receive(:param).with('token').once.and_return(@token)
250
+
251
+ @request.should_receive(:args).with(no_args).once.and_return(args)
252
+ @request.should_receive(:args=).with(clean_args).once.and_return(clean_args)
253
+ end
254
+
255
+ end
256
+
257
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --require spec/spec_helper.rb
@@ -0,0 +1,13 @@
1
+ require 'spec'
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+
5
+ require 'apache/secure_download'
6
+ require 'apache/mock_constants'
7
+
8
+ Spec::Runner.configure do |config|
9
+ config.before :each do
10
+ @now = Time.now
11
+ Time.stub!(:now).and_return { @now }
12
+ end
13
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apache_secure_download
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease: false
4
+ hash: 25
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jens Wille
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-24 00:00:00 +02:00
19
- default_executable:
18
+ date: 2011-04-29 00:00:00 Z
20
19
  dependencies: []
21
20
 
22
21
  description: Apache module providing secure downloading functionality, just like Mongrel Secure Download does for mongrel.
@@ -26,9 +25,9 @@ executables: []
26
25
  extensions: []
27
26
 
28
27
  extra_rdoc_files:
28
+ - README
29
29
  - COPYING
30
30
  - ChangeLog
31
- - README
32
31
  files:
33
32
  - lib/apache/secure_download/util.rb
34
33
  - lib/apache/secure_download/version.rb
@@ -38,20 +37,22 @@ files:
38
37
  - ChangeLog
39
38
  - Rakefile
40
39
  - COPYING
41
- has_rdoc: true
40
+ - spec/spec.opts
41
+ - spec/apache/secure_download/util_spec.rb
42
+ - spec/apache/secure_download_spec.rb
43
+ - spec/spec_helper.rb
42
44
  homepage: http://prometheus.rubyforge.org/apache_secure_download
43
45
  licenses: []
44
46
 
45
47
  post_install_message:
46
48
  rdoc_options:
49
+ - --charset
50
+ - UTF-8
47
51
  - --title
48
- - apache_secure_download Application documentation
52
+ - apache_secure_download Application documentation (v0.1.1)
49
53
  - --main
50
54
  - README
51
55
  - --line-numbers
52
- - --inline-source
53
- - --charset
54
- - UTF-8
55
56
  - --all
56
57
  require_paths:
57
58
  - lib
@@ -76,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
77
  requirements: []
77
78
 
78
79
  rubyforge_project: prometheus
79
- rubygems_version: 1.3.7
80
+ rubygems_version: 1.7.2
80
81
  signing_key:
81
82
  specification_version: 3
82
83
  summary: Apache module providing secure downloading functionality, just like Mongrel Secure Download does for mongrel.