url_store 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +25 -0
- data/Rakefile +19 -0
- data/VERSION +1 -0
- data/lib/url_store.rb +37 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/url_store_spec.rb +40 -0
- data/url_store.gemspec +47 -0
- metadata +62 -0
data/README.markdown
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Data securely stored in urls.
|
2
|
+
|
3
|
+
Install
|
4
|
+
=======
|
5
|
+
- As gem: ` sudo gem install url_store `
|
6
|
+
- As Rails plugin: ` script/plugin install git://github.com/grosser/url_store.git `
|
7
|
+
|
8
|
+
|
9
|
+
Usage
|
10
|
+
=====
|
11
|
+
# View:
|
12
|
+
<%= link_to 'paid', :controller=>:payments, :action=>:paid, :data=>UrlStore.encode(:id=>1, :status=>'paid')%>
|
13
|
+
|
14
|
+
# Controller:
|
15
|
+
if data = UrlStore.decode(params[:data])
|
16
|
+
Payment.find(data[:id]).update_attribute(:status, data[:status])
|
17
|
+
else
|
18
|
+
raise 'FRAUD!'
|
19
|
+
end
|
20
|
+
|
21
|
+
Author
|
22
|
+
=======
|
23
|
+
[Michael Grosser](http://pragmatig.wordpress.com)
|
24
|
+
grosser.michael@gmail.com
|
25
|
+
Hereby placed under public domain, do what you want, just do not hold me accountable...
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
task :default => :spec
|
2
|
+
require 'spec/rake/spectask'
|
3
|
+
Spec::Rake::SpecTask.new {|t| t.spec_opts = ['--color']}
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
project_name = 'url_store'
|
8
|
+
Jeweler::Tasks.new do |gem|
|
9
|
+
gem.name = project_name
|
10
|
+
gem.description = gem.summary = "Data securely stored in urls."
|
11
|
+
gem.email = "grosser.michael@gmail.com"
|
12
|
+
gem.homepage = "http://github.com/grosser/#{project_name}"
|
13
|
+
gem.authors = ["Michael Grosser"]
|
14
|
+
end
|
15
|
+
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install jeweler"
|
19
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/url_store.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
3
|
+
class UrlStore
|
4
|
+
VERSION = File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
|
5
|
+
SECRET = 'asdkasjlwqjdqaccxnjkasdfh2313'
|
6
|
+
METHOD = 'SHA1'
|
7
|
+
|
8
|
+
# (convert to base64url <-> RFC4648) and '|'
|
9
|
+
# which is not url-safe if you ask ERB/CGI, but browsers accept it
|
10
|
+
IN = '+/='
|
11
|
+
OUT = '-_|'
|
12
|
+
|
13
|
+
cattr_accessor :secret
|
14
|
+
self.secret = SECRET
|
15
|
+
|
16
|
+
def self.encode(data)
|
17
|
+
string = encoder.generate(data)
|
18
|
+
string = string.sub('--', ';') # seperator of verifier
|
19
|
+
string.to_s.tr(IN,OUT)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.decode(string)
|
23
|
+
string = string.to_s.tr(OUT,IN) # convert to base64url <-> RFC4648
|
24
|
+
string = string.sub(';','--') # seperator of verifier
|
25
|
+
begin
|
26
|
+
encoder.verify(string)
|
27
|
+
rescue ActiveSupport::MessageVerifier::InvalidSignature
|
28
|
+
nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def self.encoder
|
35
|
+
ActiveSupport::MessageVerifier.new(secret, METHOD)
|
36
|
+
end
|
37
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
require 'cgi'
|
3
|
+
|
4
|
+
describe UrlStore do
|
5
|
+
before do
|
6
|
+
@data = {:x => 11212, :y => 'asdasda sdasdasdASDJKSAJDLSKDLKDS', 'asdasd' => 12312312, 12.12 => 123123212312123, :asdasdasd => '2134 adasdasóáößðóöáåöäóðᜩöóöfóöåäfóöéåfó'}
|
7
|
+
end
|
8
|
+
|
9
|
+
it "generates same code for same data" do
|
10
|
+
UrlStore.encode(@data).should == UrlStore.encode(@data)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "can decode / encode" do
|
14
|
+
UrlStore.decode(UrlStore.encode(@data)).should == @data
|
15
|
+
end
|
16
|
+
|
17
|
+
it "cannot decode altered data" do
|
18
|
+
encoded = UrlStore.encode(@data)
|
19
|
+
UrlStore.decode(encoded+'x').should == nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it "uses a lot of different chars" do
|
23
|
+
UrlStore.encode(@data).split('').uniq.size.should >= 63
|
24
|
+
end
|
25
|
+
|
26
|
+
it "uses url-save characters" do
|
27
|
+
encoded = UrlStore.encode(@data)
|
28
|
+
CGI.escape(encoded).gsub('%3B',';').gsub('%7C','|').should == encoded
|
29
|
+
end
|
30
|
+
|
31
|
+
it "cannot decode with wrong secret" do
|
32
|
+
encoded = UrlStore.encode(@data)
|
33
|
+
UrlStore.secret = 'xxx'
|
34
|
+
UrlStore.decode(encoded).should == nil
|
35
|
+
end
|
36
|
+
|
37
|
+
it "has a VERSION" do
|
38
|
+
UrlStore::VERSION.should =~ /^\d+\.\d+\.\d+$/
|
39
|
+
end
|
40
|
+
end
|
data/url_store.gemspec
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{url_store}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Michael Grosser"]
|
12
|
+
s.date = %q{2010-01-19}
|
13
|
+
s.description = %q{Data securely stored in urls.}
|
14
|
+
s.email = %q{grosser.michael@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.markdown"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"README.markdown",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION",
|
22
|
+
"lib/url_store.rb",
|
23
|
+
"spec/spec_helper.rb",
|
24
|
+
"spec/url_store_spec.rb",
|
25
|
+
"url_store.gemspec"
|
26
|
+
]
|
27
|
+
s.homepage = %q{http://github.com/grosser/url_store}
|
28
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
29
|
+
s.require_paths = ["lib"]
|
30
|
+
s.rubygems_version = %q{1.3.5}
|
31
|
+
s.summary = %q{Data securely stored in urls.}
|
32
|
+
s.test_files = [
|
33
|
+
"spec/spec_helper.rb",
|
34
|
+
"spec/url_store_spec.rb"
|
35
|
+
]
|
36
|
+
|
37
|
+
if s.respond_to? :specification_version then
|
38
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
39
|
+
s.specification_version = 3
|
40
|
+
|
41
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
42
|
+
else
|
43
|
+
end
|
44
|
+
else
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: url_store
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Grosser
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-19 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Data securely stored in urls.
|
17
|
+
email: grosser.michael@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.markdown
|
24
|
+
files:
|
25
|
+
- README.markdown
|
26
|
+
- Rakefile
|
27
|
+
- VERSION
|
28
|
+
- lib/url_store.rb
|
29
|
+
- spec/spec_helper.rb
|
30
|
+
- spec/url_store_spec.rb
|
31
|
+
- url_store.gemspec
|
32
|
+
has_rdoc: true
|
33
|
+
homepage: http://github.com/grosser/url_store
|
34
|
+
licenses: []
|
35
|
+
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options:
|
38
|
+
- --charset=UTF-8
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
version:
|
53
|
+
requirements: []
|
54
|
+
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 1.3.5
|
57
|
+
signing_key:
|
58
|
+
specification_version: 3
|
59
|
+
summary: Data securely stored in urls.
|
60
|
+
test_files:
|
61
|
+
- spec/spec_helper.rb
|
62
|
+
- spec/url_store_spec.rb
|