clavem 1.4.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This file is part of the clavem gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
4
+ # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
+ #
6
+
7
+ require "spec_helper"
8
+
9
+ describe Clavem::Server do
10
+ let(:authorizer) { Clavem::Authorizer.new }
11
+
12
+ around(:each) do |example|
13
+ EM.run do
14
+ EM.start_server("localhost", 7772, Clavem::Server, authorizer)
15
+ EM.add_timer(0.1) do
16
+ @request = EventMachine::HttpRequest.new("http://localhost:7772/?#{example.metadata[:query]}").get
17
+ @request.callback { example.call }
18
+ end
19
+ end
20
+ end
21
+
22
+ describe "#initialize", query: "oauth_token=TOKEN" do
23
+ it "should save the authorizer" do
24
+ server = Clavem::Server.new("UNUSED", authorizer)
25
+ expect(server.instance_variable_get(:@authorizer)).to be(authorizer)
26
+ end
27
+ end
28
+
29
+ describe "#process_http_request" do
30
+ it "should save the token and report success", query: "oauth_token=TOKEN" do
31
+ expect(authorizer.succeeded?).to be_true
32
+ expect(authorizer.token).to eq("TOKEN")
33
+ end
34
+
35
+ it "should save the token and report failure", query: "notoken=TOKEN" do
36
+ expect(authorizer.denied?).to be_true
37
+ expect(authorizer.token).to eq(nil)
38
+ end
39
+ end
40
+ end
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  #
3
- # This file is part of the clavem gem. Copyright (C) 2013 and above Shogun <shogun_panda@me.com>.
3
+ # This file is part of the clavem gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
4
4
  # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
5
  #
6
6
 
@@ -8,7 +8,7 @@ require "pathname"
8
8
  require "simplecov"
9
9
  require "coveralls"
10
10
 
11
- Coveralls.wear!
11
+ Coveralls.wear! if ENV["CI"] || ENV["JENKINS_URL"]
12
12
 
13
13
  SimpleCov.start do
14
14
  root = Pathname.new(File.dirname(__FILE__)) + ".."
@@ -1,12 +1,13 @@
1
1
  # encoding: utf-8
2
2
  #
3
- # This file is part of the clavem gem. Copyright (C) 2013 and above Shogun <shogun_panda@me.com>.
3
+ # This file is part of the clavem gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
4
4
  # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
5
  #
6
6
 
7
7
  require "rubygems"
8
8
  require "bundler/setup"
9
9
  require "clavem"
10
+ require "em-http-request"
10
11
 
11
12
  RSpec.configure do |config|
12
13
  config.expect_with :rspec do |c|
@@ -1,16 +1,34 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ #
4
+ # This file is part of the clavem gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
5
+ # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
6
+ #
2
7
 
3
- require "webrick"
8
+ require "cgi"
9
+ require "eventmachine"
10
+ require "evma_httpserver"
4
11
 
5
- server = ::WEBrick::HTTPServer.new(Port: 2502, Logger: WEBrick::Log.new("/dev/null"), AccessLog: [nil, nil])
6
- ['INT', 'TERM', 'KILL'].each { |signal| trap(signal) { server.shutdown } }
12
+ class ClavemServer < EM::Connection
13
+ include EM::HttpServer
7
14
 
8
- server.mount_proc '/' do |request, response|
9
- url = request.query["url"] && request.query["url"].to_s.strip.length > 0 ? request.query["url"].to_s.strip : ""
10
- token = request.query["token"] && request.query["token"].to_s.strip.length > 0 ? request.query["token"].to_s.strip : nil
11
- wait = request.query["wait"].to_i
12
- sleep wait if wait > 0
13
- response.set_redirect(WEBrick::HTTPStatus::TemporaryRedirect, url + "?" + (token ? "oauth_token=#{token}" : "failure=FAILURE"))
15
+ def process_http_request
16
+ query = CGI::parse(@http_query_string)
17
+ url = query["oauth_callback"].first
18
+ token = (query["token"] || []).first
19
+ wait = (query["wait"].first || 0).to_i
20
+
21
+ sleep(wait) if wait > 0
22
+
23
+ response = EM::DelegatedHttpResponse.new(self)
24
+ response.send_redirect("%s?%s" % [url, token ? "oauth_token=#{token}" : "failure=FAILURE"])
25
+ end
14
26
  end
15
27
 
16
- server.start
28
+ ["INT", "TERM", "KILL"].each { |signal|
29
+ trap(signal) { EM.stop }
30
+ }
31
+
32
+ EM.run do
33
+ EM.start_server("0.0.0.0", 7779, ClavemServer)
34
+ end
metadata CHANGED
@@ -1,51 +1,60 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clavem
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
5
- prerelease:
4
+ version: 2.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Shogun
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-20 00:00:00.000000000 Z
11
+ date: 2013-08-21 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: mamertes
14
+ name: bovem
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
21
- version: 2.3.0
19
+ version: 3.0.2
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
29
- version: 2.3.0
26
+ version: 3.0.2
30
27
  - !ruby/object:Gem::Dependency
31
- name: webrick
28
+ name: eventmachine
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
37
- version: 1.3.1
33
+ version: 1.0.3
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
45
- version: 1.3.1
40
+ version: 1.0.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: eventmachine_httpserver
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.2.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.2.1
46
55
  description: A local callback server for oAuth web-flow.
47
56
  email:
48
- - shogun_panda@me.com
57
+ - shogun@cowtech.it
49
58
  executables:
50
59
  - clavem
51
60
  extensions: []
@@ -63,9 +72,8 @@ files:
63
72
  - doc/Clavem.html
64
73
  - doc/Clavem/Authorizer.html
65
74
  - doc/Clavem/Exceptions.html
66
- - doc/Clavem/Exceptions/AuthorizationDenied.html
67
75
  - doc/Clavem/Exceptions/Failure.html
68
- - doc/Clavem/Exceptions/Timeout.html
76
+ - doc/Clavem/Server.html
69
77
  - doc/Clavem/Version.html
70
78
  - doc/_index.html
71
79
  - doc/class_list.html
@@ -76,7 +84,6 @@ files:
76
84
  - doc/file_list.html
77
85
  - doc/frames.html
78
86
  - doc/index.html
79
- - doc/index.html.save
80
87
  - doc/js/app.js
81
88
  - doc/js/full_list.js
82
89
  - doc/js/jquery.js
@@ -84,43 +91,41 @@ files:
84
91
  - doc/top-level-namespace.html
85
92
  - lib/clavem.rb
86
93
  - lib/clavem/authorizer.rb
87
- - lib/clavem/template.html.erb
94
+ - lib/clavem/server.rb
88
95
  - lib/clavem/version.rb
89
96
  - locales/en.yml
90
97
  - locales/it.yml
91
98
  - spec/clavem/authorizer_spec.rb
99
+ - spec/clavem/server_spec.rb
92
100
  - spec/coverage_helper.rb
93
101
  - spec/spec_helper.rb
94
102
  - test_server.rb
95
103
  homepage: http://sw.cow.tc/clavem
96
104
  licenses: []
105
+ metadata: {}
97
106
  post_install_message:
98
107
  rdoc_options: []
99
108
  require_paths:
100
109
  - lib
101
110
  required_ruby_version: !ruby/object:Gem::Requirement
102
- none: false
103
111
  requirements:
104
- - - ! '>='
112
+ - - '>='
105
113
  - !ruby/object:Gem::Version
106
114
  version: 1.9.3
107
115
  required_rubygems_version: !ruby/object:Gem::Requirement
108
- none: false
109
116
  requirements:
110
- - - ! '>='
117
+ - - '>='
111
118
  - !ruby/object:Gem::Version
112
119
  version: '0'
113
- segments:
114
- - 0
115
- hash: 3703999172995824806
116
120
  requirements: []
117
121
  rubyforge_project: clavem
118
- rubygems_version: 1.8.25
122
+ rubygems_version: 2.0.6
119
123
  signing_key:
120
- specification_version: 3
124
+ specification_version: 4
121
125
  summary: A local callback server for oAuth web-flow.
122
126
  test_files:
123
127
  - spec/clavem/authorizer_spec.rb
128
+ - spec/clavem/server_spec.rb
124
129
  - spec/coverage_helper.rb
125
130
  - spec/spec_helper.rb
126
131
  has_rdoc:
@@ -1,133 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
- <head>
5
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
- <title>
7
- Exception: Clavem::Exceptions::AuthorizationDenied
8
-
9
- &mdash; Documentation by YARD 0.8.6.2
10
-
11
- </title>
12
-
13
- <link rel="stylesheet" href="../../css/style.css" type="text/css" charset="utf-8" />
14
-
15
- <link rel="stylesheet" href="../../css/common.css" type="text/css" charset="utf-8" />
16
-
17
- <script type="text/javascript" charset="utf-8">
18
- hasFrames = window.top.frames.main ? true : false;
19
- relpath = '../../';
20
- framesUrl = "../../frames.html#!" + escape(window.location.href);
21
- </script>
22
-
23
-
24
- <script type="text/javascript" charset="utf-8" src="../../js/jquery.js"></script>
25
-
26
- <script type="text/javascript" charset="utf-8" src="../../js/app.js"></script>
27
-
28
-
29
- </head>
30
- <body>
31
- <div id="header">
32
- <div id="menu">
33
-
34
- <a href="../../_index.html">Index (A)</a> &raquo;
35
- <span class='title'><span class='object_link'><a href="../../Clavem.html" title="Clavem (module)">Clavem</a></span></span> &raquo; <span class='title'><span class='object_link'><a href="../Exceptions.html" title="Clavem::Exceptions (module)">Exceptions</a></span></span>
36
- &raquo;
37
- <span class="title">AuthorizationDenied</span>
38
-
39
-
40
- <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
41
- </div>
42
-
43
- <div id="search">
44
-
45
- <a class="full_list_link" id="class_list_link"
46
- href="../../class_list.html">
47
- Class List
48
- </a>
49
-
50
- <a class="full_list_link" id="method_list_link"
51
- href="../../method_list.html">
52
- Method List
53
- </a>
54
-
55
- <a class="full_list_link" id="file_list_link"
56
- href="../../file_list.html">
57
- File List
58
- </a>
59
-
60
- </div>
61
- <div class="clear"></div>
62
- </div>
63
-
64
- <iframe id="search_frame"></iframe>
65
-
66
- <div id="content"><h1>Exception: Clavem::Exceptions::AuthorizationDenied
67
-
68
-
69
-
70
- </h1>
71
-
72
- <dl class="box">
73
-
74
- <dt class="r1">Inherits:</dt>
75
- <dd class="r1">
76
- <span class="inheritName">RuntimeError</span>
77
-
78
- <ul class="fullTree">
79
- <li>Object</li>
80
-
81
- <li class="next">RuntimeError</li>
82
-
83
- <li class="next">Clavem::Exceptions::AuthorizationDenied</li>
84
-
85
- </ul>
86
- <a href="#" class="inheritanceTree">show all</a>
87
-
88
- </dd>
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
- <dt class="r2 last">Defined in:</dt>
99
- <dd class="r2 last">lib/clavem/authorizer.rb</dd>
100
-
101
- </dl>
102
- <div class="clear"></div>
103
-
104
- <h2>Overview</h2><div class="docstring">
105
- <div class="discussion">
106
- <p>This exception is raised if the authorization was denied.</p>
107
-
108
-
109
- </div>
110
- </div>
111
- <div class="tags">
112
-
113
-
114
- </div>
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
-
124
- </div>
125
-
126
- <div id="footer">
127
- Generated on Sat Jul 20 13:46:58 2013 by
128
- <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
129
- 0.8.6.2 (ruby-1.9.3).
130
- </div>
131
-
132
- </body>
133
- </html>
@@ -1,133 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
- <head>
5
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
- <title>
7
- Exception: Clavem::Exceptions::Timeout
8
-
9
- &mdash; Documentation by YARD 0.8.6.2
10
-
11
- </title>
12
-
13
- <link rel="stylesheet" href="../../css/style.css" type="text/css" charset="utf-8" />
14
-
15
- <link rel="stylesheet" href="../../css/common.css" type="text/css" charset="utf-8" />
16
-
17
- <script type="text/javascript" charset="utf-8">
18
- hasFrames = window.top.frames.main ? true : false;
19
- relpath = '../../';
20
- framesUrl = "../../frames.html#!" + escape(window.location.href);
21
- </script>
22
-
23
-
24
- <script type="text/javascript" charset="utf-8" src="../../js/jquery.js"></script>
25
-
26
- <script type="text/javascript" charset="utf-8" src="../../js/app.js"></script>
27
-
28
-
29
- </head>
30
- <body>
31
- <div id="header">
32
- <div id="menu">
33
-
34
- <a href="../../_index.html">Index (T)</a> &raquo;
35
- <span class='title'><span class='object_link'><a href="../../Clavem.html" title="Clavem (module)">Clavem</a></span></span> &raquo; <span class='title'><span class='object_link'><a href="../Exceptions.html" title="Clavem::Exceptions (module)">Exceptions</a></span></span>
36
- &raquo;
37
- <span class="title">Timeout</span>
38
-
39
-
40
- <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
41
- </div>
42
-
43
- <div id="search">
44
-
45
- <a class="full_list_link" id="class_list_link"
46
- href="../../class_list.html">
47
- Class List
48
- </a>
49
-
50
- <a class="full_list_link" id="method_list_link"
51
- href="../../method_list.html">
52
- Method List
53
- </a>
54
-
55
- <a class="full_list_link" id="file_list_link"
56
- href="../../file_list.html">
57
- File List
58
- </a>
59
-
60
- </div>
61
- <div class="clear"></div>
62
- </div>
63
-
64
- <iframe id="search_frame"></iframe>
65
-
66
- <div id="content"><h1>Exception: Clavem::Exceptions::Timeout
67
-
68
-
69
-
70
- </h1>
71
-
72
- <dl class="box">
73
-
74
- <dt class="r1">Inherits:</dt>
75
- <dd class="r1">
76
- <span class="inheritName">Exception</span>
77
-
78
- <ul class="fullTree">
79
- <li>Object</li>
80
-
81
- <li class="next">Exception</li>
82
-
83
- <li class="next">Clavem::Exceptions::Timeout</li>
84
-
85
- </ul>
86
- <a href="#" class="inheritanceTree">show all</a>
87
-
88
- </dd>
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
- <dt class="r2 last">Defined in:</dt>
99
- <dd class="r2 last">lib/clavem/authorizer.rb</dd>
100
-
101
- </dl>
102
- <div class="clear"></div>
103
-
104
- <h2>Overview</h2><div class="docstring">
105
- <div class="discussion">
106
- <p>This exception is raised if the timeout expired.</p>
107
-
108
-
109
- </div>
110
- </div>
111
- <div class="tags">
112
-
113
-
114
- </div>
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
-
124
- </div>
125
-
126
- <div id="footer">
127
- Generated on Sat Jul 20 13:46:58 2013 by
128
- <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
129
- 0.8.6.2 (ruby-1.9.3).
130
- </div>
131
-
132
- </body>
133
- </html>