auth_manager 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b8521841e5314b1d118d3065deeacb4c9784a4dc
4
+ data.tar.gz: 6d732386347e5c838d88d64195b10dfb8f2a5fd1
5
+ SHA512:
6
+ metadata.gz: e06913f4662d119d8fb4a572000645a69e67359136813721028c8205c19d6bc2970b7b6b48a9042c3b65c07ff3f349cd55426c4e09c63da6ce53f7fc2feaa171
7
+ data.tar.gz: d282c24bf6db2e084b93d7ab48625859483ff85ea00b93801475f297fac02d4190652546a8e5e46a4f9c11b9b30e681cfd54d99c4c62d5341460d495939ed36a
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in auth_manager.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # AuthManager
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'auth_manager'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install auth_manager
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/auth_manager/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'auth_manager/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "auth_manager"
8
+ spec.version = AuthManager::VERSION
9
+ spec.authors = ["atacraft && fabira"]
10
+ spec.email = ["atacraft@gmail.com, fabira90@gmail.com"]
11
+ spec.summary = %q{"Module auth_manager"}
12
+ spec.description = %q{"Authenticate developpers and applications."}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake", "~> 0"
23
+ spec.add_development_dependency "redis","~>3.0", ">= 3.0.7"
24
+
25
+ #(we added) development dependencies
26
+ spec.required_ruby_version = ">= 2.0"
27
+ spec.add_development_dependency "rspec", "~>2.6"
28
+
29
+ end
data/dump.rdb ADDED
Binary file
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ require 'redis'
3
+ require_relative '../base.rb'
4
+
5
+ class Add < AuthManager::Validation
6
+
7
+ def save?(given_user, option={user: true, app: false})
8
+ user = option.fetch(:user) || false
9
+ app = option.fetch(:app) || false
10
+ validate_param( given_user, option, user, app )
11
+ save(user, given_user)
12
+ end
13
+
14
+ private
15
+
16
+ def save_this(liste, params)
17
+ @redis.sadd(liste, params)
18
+ end
19
+
20
+ def save(user, params)
21
+ liste = user ? USERS : APPS
22
+ save_this(liste, params)
23
+ end
24
+
25
+ end
@@ -0,0 +1,39 @@
1
+ module AuthManager
2
+ class Base
3
+ attr_accessor :redis
4
+
5
+ USERS = 'users'
6
+ APPS = 'applications'
7
+
8
+ def initialize
9
+ @redis = Redis.current
10
+ end
11
+
12
+ end
13
+
14
+ class Validation < Base
15
+
16
+ def validate_param(param, option, user, app)
17
+ validate_option(option, user, app)
18
+ valid_param = JSON.parse(param)
19
+ option[:user] ? user_as_param(valid_param) : app_as_param(valid_param)
20
+ end
21
+
22
+ def user_as_param(valid_param)
23
+ if (valid_param['login'] && valid_param['login'].empty?) || (valid_param['password'] && valid_param['password'].empty?)
24
+ false
25
+ end
26
+ end
27
+
28
+ def app_as_param(valid_param)
29
+ if valid_param['api_key'] && valid_param['api_key'].empty?
30
+ false
31
+ end
32
+ end
33
+
34
+ def validate_option(option, user, app)
35
+ false unless option.instance_of?(Hash)
36
+ false if (user && app)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ require 'redis'
3
+ require_relative '../base'
4
+
5
+ class Delete < AuthManager::Base
6
+
7
+ def delete?(obj_to_del, option)
8
+ new_obj = format_new_obj(obj_to_del)
9
+ fake_delete?(obj_to_del, new_obj, option)
10
+ end
11
+
12
+ private
13
+
14
+ def fake_delete?(obj_to_del, new_obj, option)
15
+ update = Update.new
16
+ update.update(obj_to_del, new_obj, option)
17
+ end
18
+
19
+ def format_new_obj(obj_to_del)
20
+ json_obj = JSON.parse(obj_to_del)
21
+ if json_obj['api_key']
22
+ {api_key: json_obj['api_key'], deleted: true }.to_json
23
+ else
24
+ {login: json_obj['login'], password: json_obj['password'], deleted: true }.to_json
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,14 @@
1
+ require 'redis'
2
+ require_relative '../base.rb'
3
+
4
+ class Find < AuthManager::Validation
5
+
6
+ def find_object?( param, option )
7
+ user = option.fetch(:user) || false
8
+ app = option.fetch(:app) || false
9
+ validate_param(param, option, user, app)
10
+ liste = user ? USERS : APPS
11
+ @redis.sismember( liste, param ) ? true : false
12
+ end
13
+
14
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ require 'redis'
3
+ require_relative '../base'
4
+
5
+ class Update < AuthManager::Base
6
+
7
+ def update(old_obj, new_obj, option)
8
+ existing_obj?(old_obj, option)
9
+ write_new_info?(new_obj, option)
10
+ delete_obj?(old_obj, option)
11
+ end
12
+
13
+ private
14
+
15
+ def existing_obj?(old_obj, option)
16
+ find = Find.new
17
+ find.find_object?(old_obj, option)
18
+ end
19
+
20
+ def delete_obj?(old_obj, option)
21
+ user = option.fetch(:user) || false
22
+ liste = user ? USERS : APPS
23
+ @redis.srem(liste, old_obj)
24
+ end
25
+
26
+ def write_new_info?(new_obj, option)
27
+ add = Add.new
28
+ add.save?(new_obj, option)
29
+ end
30
+
31
+ end
@@ -0,0 +1,3 @@
1
+ module AuthManager
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,9 @@
1
+ require 'auth_manager/version'
2
+ require 'auth_manager/add/add'
3
+ require 'auth_manager/find/find'
4
+ require 'auth_manager/update/update'
5
+ require 'auth_manager/delete/delete'
6
+
7
+ module AuthManager
8
+ # Your code goes here...
9
+ end
data/specs/add_spec.rb ADDED
@@ -0,0 +1,36 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe Add do
4
+ let(:add) { Add.new }
5
+ #valid variables
6
+ let(:valid_user) { { login: 'nano', password: 'password' }.to_json }
7
+ let(:valid_app) { { api_key: 'api_key' }.to_json }
8
+ let(:valid_user_opt) { {user: true, app: false} }
9
+ let(:valid_app_opt) { { user: false, app: true } }
10
+
11
+ describe '.initialize' do
12
+ context 'When created' do
13
+ it { expect(add.redis).to_not be_nil }
14
+ end
15
+ end
16
+
17
+ describe '#save?' do
18
+ #cleaning valid_user and or valid app before new save
19
+ before(:each) do
20
+ add.redis.del('users', valid_user)
21
+ add.redis.del('applications', valid_app)
22
+ end
23
+ #normal cases
24
+ context 'When saved a valid user' do
25
+ it { expect(add.save?(valid_user, valid_user_opt)).to be_true }
26
+ end
27
+ context 'When saved a valid user with default option' do
28
+ it { expect(add.save?(valid_user)).to be_true }
29
+ end
30
+ context 'When saved a valid app' do
31
+ it { expect(add.save?(valid_app, valid_app_opt)).to be_true }
32
+ end
33
+
34
+ end
35
+
36
+ end
@@ -0,0 +1,24 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe Delete do
4
+ let(:delete) { Delete.new }
5
+ let(:user_to_del) { {login: 'login', password: 'password'}.to_json }
6
+ let(:app_to_del) { {api_key: 'api_key'}.to_json }
7
+ let(:user_option) { { user: true, app: false } }
8
+ let(:app_option) { { user: false, app: true } }
9
+ describe '#delete' do
10
+ before(:each) do
11
+ delete.redis.del('users')
12
+ delete.redis.del('applications')
13
+ delete.redis.sadd('users', user_to_del)
14
+ delete.redis.sadd('applications', app_to_del)
15
+ end
16
+
17
+ context 'When deleted a user' do
18
+ it { expect(delete.delete?(user_to_del, user_option)).to be_true }
19
+ end
20
+ context 'When deleted an app' do
21
+ it { expect(delete.delete?(app_to_del, app_option)).to be_true }
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,42 @@
1
+ require 'redis'
2
+ require 'json'
3
+
4
+ class Populate
5
+
6
+ redis = Redis.current
7
+ #setting some initial variable to allow looping and dynamic keys
8
+ #and fields generation
9
+ #
10
+ #Users login params
11
+ ind = 0
12
+ users_collection = 'users'
13
+ login = 'login'
14
+ password = 'password'
15
+
16
+ #Apps login params
17
+
18
+ apps_collection = 'apps'
19
+ api_key = 'api_key:'
20
+
21
+ #Creating 4 users and apps
22
+ #Each user has a user + ind key, a login + ind login and a password + ind password
23
+ 4.times do
24
+ #users creation
25
+ login = login + ind.to_s
26
+ password = password + ind.to_s
27
+ user = { login: login, password: password }.to_json
28
+ #using redis hashes to store objects like users
29
+
30
+ p 'Adding user n°' + ind.to_s
31
+ p redis.sadd(users_collection, user)
32
+ #apps creation
33
+ api_key = api_key + ind.to_s
34
+ app = { api_key: api_key }.to_json
35
+ #using redis hashes to store one value
36
+ p 'Adding app n°' + ind.to_s
37
+ p redis.sadd(apps_collection, app)
38
+
39
+ ind = ind + 1
40
+ end
41
+
42
+ end
@@ -0,0 +1,32 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe Find do
4
+ let(:find) { Find.new }
5
+ let(:invalid_user) { { login: 'login', password: 'password' }.to_json }
6
+ let(:valid_user){ { login: 'tata', password: 'toto' }.to_json }
7
+ let(:valid_app) { { api_key: 'api_key' }.to_json }
8
+ let(:invalid_app) { { api_key: 'not_api_key' }.to_json }
9
+ let(:user_opt) { { user: true, app: false } }
10
+ let(:app_opt) { { user: false, app: true } }
11
+ describe '#find_object?' do
12
+ context 'When user is found' do
13
+ before(:each) do
14
+ find.redis.del('users')
15
+ find.redis.del('applications')
16
+ find.redis.sadd('users', valid_user)
17
+ find.redis.sadd('applications', valid_app)
18
+ end
19
+ it { expect( find.find_object?(valid_user, user_opt ) ).to be_true }
20
+ end
21
+ context 'When user is not found' do
22
+ it { expect( find.find_object?( invalid_user, user_opt ) ).to be_false }
23
+ end
24
+
25
+ context 'When app is found' do
26
+ it { expect( find.find_object?(valid_app, app_opt ) ).to be_true }
27
+ end
28
+ context 'When app is not found' do
29
+ it { expect( find.find_object?( invalid_app, app_opt ) ).to be_false }
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,2 @@
1
+ require 'auth_manager'
2
+ require 'json'
@@ -0,0 +1 @@
1
+ require_relative './fixtures/environment'
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ require_relative 'spec_helper'
3
+
4
+ describe Update do
5
+ let(:update) { Update.new }
6
+ let(:new_user_info) { {login: 'new login', password: 'new password'}.to_json }
7
+ let(:new_app_info) { { api_key: 'new api key' }.to_json }
8
+ let(:valid_old_app) { { api_key: 'api_key' }.to_json }
9
+ let(:invalid_old_app) { { api_key: 'bad_key' }.to_json }
10
+ let(:valid_old_user) { { login: 'login', password: 'password' }.to_json}
11
+ let(:invalid_old_user) { {login: 'not a login', password: 'not a password'}.to_json }
12
+ let(:user_option) { { user: true, app: false } }
13
+ let(:app_option) { { user: false, app: true } }
14
+ describe '#update' do
15
+ before(:each) do
16
+ update.redis.del('users')
17
+ update.redis.del('applications')
18
+ update.redis.sadd('users', valid_old_user)
19
+ update.redis.sadd('applications', valid_old_app)
20
+ end
21
+ context 'When user object is updated' do
22
+ it { expect(update.update(valid_old_user, new_user_info, user_option)).to be_true }
23
+ end
24
+ context 'When app object is updated' do
25
+ it { expect(update.update(valid_old_app, new_app_info, app_option)).to be_true }
26
+ end
27
+ context 'When user object is not updated' do
28
+ it { expect(update.update(invalid_old_user, new_user_info, user_option)).to be_false }
29
+ end
30
+ context 'When app object is not updated' do
31
+ it { expect(update.update(invalid_old_app, new_app_info, app_option)).to be_false }
32
+ end
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: auth_manager
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - atacraft && fabira
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: redis
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 3.0.7
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '3.0'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 3.0.7
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '2.6'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '2.6'
75
+ description: '"Authenticate developpers and applications."'
76
+ email:
77
+ - atacraft@gmail.com, fabira90@gmail.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".gitignore"
83
+ - Gemfile
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - auth_manager.gemspec
88
+ - dump.rdb
89
+ - lib/auth_manager.rb
90
+ - lib/auth_manager/add/add.rb
91
+ - lib/auth_manager/base.rb
92
+ - lib/auth_manager/delete/delete.rb
93
+ - lib/auth_manager/find/find.rb
94
+ - lib/auth_manager/update/update.rb
95
+ - lib/auth_manager/version.rb
96
+ - specs/add_spec.rb
97
+ - specs/delete_spec.rb
98
+ - specs/feed/populate.rb
99
+ - specs/find_spec.rb
100
+ - specs/fixtures/environment.rb
101
+ - specs/spec_helper.rb
102
+ - specs/update_spec.rb
103
+ homepage: ''
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '2.0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.2.2
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: '"Module auth_manager"'
127
+ test_files: []