mno-enterprise-core 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +1 -0
- data/Rakefile +12 -0
- data/app/assets/images/mno_enterprise/main-logo.png +0 -0
- data/app/controllers/mno_enterprise/application_controller.rb +116 -0
- data/app/helpers/mno_enterprise/application_helper.rb +67 -0
- data/app/helpers/mno_enterprise/impersonate_helper.rb +27 -0
- data/app/models/mno_enterprise/ability.rb +6 -0
- data/app/models/mno_enterprise/app.rb +72 -0
- data/app/models/mno_enterprise/app_instance.rb +36 -0
- data/app/models/mno_enterprise/app_instances_sync.rb +6 -0
- data/app/models/mno_enterprise/arrears_situation.rb +6 -0
- data/app/models/mno_enterprise/audit_event.rb +21 -0
- data/app/models/mno_enterprise/base_resource.rb +228 -0
- data/app/models/mno_enterprise/credit_card.rb +40 -0
- data/app/models/mno_enterprise/deletion_request.rb +35 -0
- data/app/models/mno_enterprise/impac/dashboard.rb +36 -0
- data/app/models/mno_enterprise/impac/dashboard_provisioner.rb +5 -0
- data/app/models/mno_enterprise/impac/kpi.rb +9 -0
- data/app/models/mno_enterprise/impac/widget.rb +13 -0
- data/app/models/mno_enterprise/invoice.rb +53 -0
- data/app/models/mno_enterprise/org_invite.rb +50 -0
- data/app/models/mno_enterprise/organization.rb +33 -0
- data/app/models/mno_enterprise/team.rb +50 -0
- data/app/models/mno_enterprise/tenant.rb +5 -0
- data/app/models/mno_enterprise/tenant_invoice.rb +5 -0
- data/app/models/mno_enterprise/user.rb +183 -0
- data/app/pdf/mno_enterprise/invoice_pdf.rb +516 -0
- data/config/initializers/audit_log.rb +5 -0
- data/config/locales/devise.en.yml +60 -0
- data/config/routes.rb +2 -0
- data/config/styleguide.yml +106 -0
- data/lib/accountingjs_serializer.rb +51 -0
- data/lib/devise/controllers/extension_helpers.rb +52 -0
- data/lib/devise/extension_routes.rb +11 -0
- data/lib/devise/hooks/password_expirable.rb +5 -0
- data/lib/devise/models/password_expirable.rb +28 -0
- data/lib/devise/models/remote_authenticatable.rb +48 -0
- data/lib/devise/strategies/remote_authenticatable.rb +44 -0
- data/lib/devise_extension.rb +36 -0
- data/lib/faraday/adapter/net_http_no_proxy.rb +19 -0
- data/lib/generators/mno_enterprise/database_extension/USAGE +11 -0
- data/lib/generators/mno_enterprise/database_extension/database_extension_generator.rb +36 -0
- data/lib/generators/mno_enterprise/database_extension/templates/model.rb +9 -0
- data/lib/generators/mno_enterprise/dummy/dummy_generator.rb +98 -0
- data/lib/generators/mno_enterprise/dummy/templates/rails/application.rb.erb +9 -0
- data/lib/generators/mno_enterprise/dummy/templates/rails/boot.rb.erb +6 -0
- data/lib/generators/mno_enterprise/dummy/templates/rails/database.yml +22 -0
- data/lib/generators/mno_enterprise/dummy/templates/rails/routes.rb +8 -0
- data/lib/generators/mno_enterprise/dummy/templates/rails/test-env.rb +45 -0
- data/lib/generators/mno_enterprise/install/install_generator.rb +140 -0
- data/lib/generators/mno_enterprise/install/templates/Procfile +1 -0
- data/lib/generators/mno_enterprise/install/templates/config/initializers/mno_enterprise.rb +135 -0
- data/lib/generators/mno_enterprise/install/templates/config/mno_enterprise_styleguide.yml +104 -0
- data/lib/generators/mno_enterprise/install/templates/javascripts/mno_enterprise_extensions.js +7 -0
- data/lib/generators/mno_enterprise/install/templates/stylesheets/main.less_erb +25 -0
- data/lib/generators/mno_enterprise/install/templates/stylesheets/theme.less_erb +59 -0
- data/lib/generators/mno_enterprise/install/templates/stylesheets/variables.less +337 -0
- data/lib/generators/mno_enterprise/install/templates/tasks/sprites.rake +14 -0
- data/lib/generators/mno_enterprise/puma_stack/puma_stack_generator.rb +58 -0
- data/lib/generators/mno_enterprise/templates/scripts/monit/app-server.conf +8 -0
- data/lib/generators/mno_enterprise/templates/scripts/nginx/app +51 -0
- data/lib/generators/mno_enterprise/templates/scripts/puma.rb +25 -0
- data/lib/generators/mno_enterprise/templates/scripts/setup.sh +27 -0
- data/lib/generators/mno_enterprise/templates/scripts/upstart/app-web-hotrestart.conf +26 -0
- data/lib/generators/mno_enterprise/templates/scripts/upstart/app-web-server.conf +34 -0
- data/lib/generators/mno_enterprise/templates/scripts/upstart/app-web.conf +2 -0
- data/lib/generators/mno_enterprise/templates/scripts/upstart/app.conf +11 -0
- data/lib/her_extension/her_orm_adapter.rb +54 -0
- data/lib/her_extension/middleware/mnoe_api_v1_parse_json.rb +54 -0
- data/lib/her_extension/model/associations/association.rb +61 -0
- data/lib/her_extension/model/associations/association_proxy.rb +34 -0
- data/lib/her_extension/model/associations/has_many_association.rb +115 -0
- data/lib/her_extension/model/attributes.rb +43 -0
- data/lib/her_extension/model/orm.rb +59 -0
- data/lib/her_extension/model/parse.rb +40 -0
- data/lib/her_extension/model/relation.rb +92 -0
- data/lib/her_extension/validations/remote_uniqueness_validation.rb +33 -0
- data/lib/html_processor.rb +106 -0
- data/lib/mandrill_client.rb +58 -0
- data/lib/mno-enterprise-core.rb +1 -0
- data/lib/mno_enterprise/concerns.rb +4 -0
- data/lib/mno_enterprise/concerns/controllers.rb +6 -0
- data/lib/mno_enterprise/concerns/controllers/angular_csrf.rb +59 -0
- data/lib/mno_enterprise/concerns/controllers/auth.rb +9 -0
- data/lib/mno_enterprise/concerns/controllers/auth/confirmations_controller.rb +187 -0
- data/lib/mno_enterprise/concerns/controllers/auth/passwords_controller.rb +54 -0
- data/lib/mno_enterprise/concerns/controllers/auth/registrations_controller.rb +136 -0
- data/lib/mno_enterprise/concerns/controllers/auth/sessions_controller.rb +54 -0
- data/lib/mno_enterprise/concerns/controllers/auth/unlocks_controller.rb +50 -0
- data/lib/mno_enterprise/concerns/models.rb +6 -0
- data/lib/mno_enterprise/concerns/models/ability.rb +108 -0
- data/lib/mno_enterprise/concerns/models/app_instance.rb +100 -0
- data/lib/mno_enterprise/concerns/models/organization.rb +102 -0
- data/lib/mno_enterprise/core.rb +279 -0
- data/lib/mno_enterprise/database_extendable.rb +57 -0
- data/lib/mno_enterprise/engine.rb +33 -0
- data/lib/mno_enterprise/testing_support/ability_test_helper.rb +10 -0
- data/lib/mno_enterprise/testing_support/common_rake.rb +19 -0
- data/lib/mno_enterprise/testing_support/factories.rb +13 -0
- data/lib/mno_enterprise/testing_support/factories/app_instances.rb +30 -0
- data/lib/mno_enterprise/testing_support/factories/apps.rb +45 -0
- data/lib/mno_enterprise/testing_support/factories/arrears_situation.rb +14 -0
- data/lib/mno_enterprise/testing_support/factories/audit_event.rb +15 -0
- data/lib/mno_enterprise/testing_support/factories/credit_card.rb +33 -0
- data/lib/mno_enterprise/testing_support/factories/deletion_request.rb +17 -0
- data/lib/mno_enterprise/testing_support/factories/impac/dashboards.rb +15 -0
- data/lib/mno_enterprise/testing_support/factories/impac/kpis.rb +20 -0
- data/lib/mno_enterprise/testing_support/factories/impac/widgets.rb +15 -0
- data/lib/mno_enterprise/testing_support/factories/invoices.rb +51 -0
- data/lib/mno_enterprise/testing_support/factories/org_invite.rb +24 -0
- data/lib/mno_enterprise/testing_support/factories/organizations.rb +25 -0
- data/lib/mno_enterprise/testing_support/factories/team.rb +17 -0
- data/lib/mno_enterprise/testing_support/factories/tenant.rb +12 -0
- data/lib/mno_enterprise/testing_support/factories/tenant_invoice.rb +29 -0
- data/lib/mno_enterprise/testing_support/factories/users.rb +48 -0
- data/lib/mno_enterprise/testing_support/jpi_v1_test_helper.rb +49 -0
- data/lib/mno_enterprise/testing_support/mno_enterprise_api_test_helper.rb +167 -0
- data/lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb +173 -0
- data/lib/mno_enterprise/testing_support/organizations_shared_helpers.rb +175 -0
- data/lib/mno_enterprise/testing_support/user_action_shared.rb +47 -0
- data/lib/mno_enterprise/version.rb +3 -0
- data/lib/tasks/mno_enterprise_tasks.rake +22 -0
- data/spec/controllers/mno_enterprise/angular_csrf_spec.rb +42 -0
- data/spec/lib/her_extension/her_orm_adapter.rb +7 -0
- data/spec/lib/her_extension/model/relation_spec.rb +7 -0
- data/spec/lib/mandrill_client_spec.rb +64 -0
- data/spec/mno_enterprise_spec.rb +79 -0
- data/spec/models/mno_enterprise/app_instance_spec.rb +7 -0
- data/spec/models/mno_enterprise/app_spec.rb +62 -0
- data/spec/models/mno_enterprise/base_resource_spec.rb +28 -0
- data/spec/models/mno_enterprise/deletion_request_spec.rb +26 -0
- data/spec/models/mno_enterprise/invoice_spec.rb +7 -0
- data/spec/models/mno_enterprise/organization_spec.rb +7 -0
- data/spec/models/mno_enterprise/user_spec.rb +44 -0
- data/spec/rails_helper.rb +73 -0
- data/spec/spec_helper.rb +78 -0
- metadata +421 -0
@@ -0,0 +1,175 @@
|
|
1
|
+
module MnoEnterprise::TestingSupport::OrganizationsSharedHelpers
|
2
|
+
|
3
|
+
def partial_hash_for_credit_card(cc)
|
4
|
+
{
|
5
|
+
'credit_card' => {
|
6
|
+
'id' => cc.id,
|
7
|
+
'title' => cc.title,
|
8
|
+
'first_name' => cc.first_name,
|
9
|
+
'last_name' => cc.last_name,
|
10
|
+
'number' => cc.masked_number,
|
11
|
+
'month' => cc.month,
|
12
|
+
'year' => cc.year,
|
13
|
+
'country' => cc.country,
|
14
|
+
'verification_value' => 'CVV',
|
15
|
+
'billing_address' => cc.billing_address,
|
16
|
+
'billing_city' => cc.billing_city,
|
17
|
+
'billing_postcode' => cc.billing_postcode,
|
18
|
+
'billing_country' => cc.billing_country
|
19
|
+
}
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def partial_hash_for_members(organization, admin = false)
|
24
|
+
list = []
|
25
|
+
organization.users.each do |user|
|
26
|
+
u = {
|
27
|
+
'id' => user.id,
|
28
|
+
'entity' => 'User',
|
29
|
+
'name' => user.name,
|
30
|
+
'surname' => user.surname,
|
31
|
+
'email' => user.email,
|
32
|
+
'role' => user.role(organization)
|
33
|
+
}
|
34
|
+
u.merge!('uid' => user.uid) if admin
|
35
|
+
list.push(u)
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
organization.org_invites.each do |invite|
|
40
|
+
list.push({
|
41
|
+
'id' => invite.id,
|
42
|
+
'entity' => 'OrgInvite',
|
43
|
+
'email' => invite.user_email,
|
44
|
+
'role' => invite.user_role
|
45
|
+
})
|
46
|
+
end
|
47
|
+
|
48
|
+
return list
|
49
|
+
end
|
50
|
+
|
51
|
+
def partial_hash_for_organization(organization, admin = false)
|
52
|
+
ret = {
|
53
|
+
'id' => organization.id,
|
54
|
+
'name' => organization.name,
|
55
|
+
'soa_enabled' => organization.soa_enabled
|
56
|
+
}
|
57
|
+
|
58
|
+
if admin
|
59
|
+
ret.merge!({
|
60
|
+
'uid' => organization.uid
|
61
|
+
})
|
62
|
+
end
|
63
|
+
|
64
|
+
ret
|
65
|
+
end
|
66
|
+
|
67
|
+
def partial_hash_for_current_user(organization, user)
|
68
|
+
{
|
69
|
+
'id' => user.id,
|
70
|
+
'name' => user.name,
|
71
|
+
'surname' => user.surname,
|
72
|
+
'email' => user.email,
|
73
|
+
'role' => user.role(organization)
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
def partial_hash_for_billing(organization)
|
78
|
+
{
|
79
|
+
'billing' => {
|
80
|
+
'current' => organization.current_billing,
|
81
|
+
'credit' => organization.current_credit
|
82
|
+
}
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
def partial_hash_for_invoices(organization)
|
87
|
+
hash = {'invoices' => []}
|
88
|
+
organization.invoices.order("ended_at DESC").each do |invoice|
|
89
|
+
hash['invoices'].push({
|
90
|
+
'period' => invoice.period_label,
|
91
|
+
'amount' => invoice.total_due,
|
92
|
+
'paid' => invoice.paid?,
|
93
|
+
'link' => mnoe_enterprise.invoice_path(invoice.slug),
|
94
|
+
})
|
95
|
+
end
|
96
|
+
|
97
|
+
return hash
|
98
|
+
end
|
99
|
+
|
100
|
+
def hash_for_organizations(organizations, admin = false)
|
101
|
+
{
|
102
|
+
'organizations' => organizations.map { |o| partial_hash_for_organization(o, admin) }
|
103
|
+
}
|
104
|
+
end
|
105
|
+
|
106
|
+
def hash_for_reduced_organization(organization)
|
107
|
+
{
|
108
|
+
'organization' => partial_hash_for_organization(organization)
|
109
|
+
}
|
110
|
+
end
|
111
|
+
|
112
|
+
def hash_for_organization(organization, user, admin = false)
|
113
|
+
hash = {
|
114
|
+
'organization' => partial_hash_for_organization(organization),
|
115
|
+
'current_user' => partial_hash_for_current_user(organization, user)
|
116
|
+
}
|
117
|
+
hash['organization'].merge!(
|
118
|
+
'members' => partial_hash_for_members(organization)
|
119
|
+
)
|
120
|
+
|
121
|
+
if user.role(organization) == 'Super Admin'
|
122
|
+
hash.merge!(partial_hash_for_billing(organization))
|
123
|
+
hash.merge!(partial_hash_for_invoices(organization))
|
124
|
+
|
125
|
+
if (cc = organization.credit_card)
|
126
|
+
hash.merge!(partial_hash_for_credit_card(cc))
|
127
|
+
end
|
128
|
+
|
129
|
+
if (situations = organization.arrears_situations)
|
130
|
+
hash.merge!(partial_hash_for_arrears_situations(situations))
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
return hash
|
135
|
+
end
|
136
|
+
|
137
|
+
def admin_hash_for_organization(organization)
|
138
|
+
hash = {}
|
139
|
+
hash['organization'] = partial_hash_for_organization(organization, true)
|
140
|
+
hash['organization'].merge!('members' => partial_hash_for_members(organization, true))
|
141
|
+
hash['organization'].merge!('credit_card' => {'presence' => false})
|
142
|
+
hash['organization'].merge!(admin_partial_hash_for_invoices(organization))
|
143
|
+
hash['organization'].merge!(admin_partial_hash_for_active_apps(organization))
|
144
|
+
hash
|
145
|
+
end
|
146
|
+
|
147
|
+
def admin_partial_hash_for_invoices(organization)
|
148
|
+
hash = {'invoices' => []}
|
149
|
+
organization.invoices.order("ended_at DESC").each do |invoice|
|
150
|
+
hash['invoices'].push({
|
151
|
+
'started_at' => invoice.started_at,
|
152
|
+
'ended_at' => invoice.ended_at,
|
153
|
+
'amount' => AccountingjsSerializer.serialize(invoice.total_due),
|
154
|
+
'paid' => invoice.paid?
|
155
|
+
})
|
156
|
+
end
|
157
|
+
hash
|
158
|
+
end
|
159
|
+
|
160
|
+
def admin_partial_hash_for_active_apps(organization)
|
161
|
+
hash = {'active_apps' => []}
|
162
|
+
organization.app_instances.select { |app| app.status == "running" }.each do |active_apps|
|
163
|
+
hash['active_apps'].push({
|
164
|
+
'id' => active_apps.id,
|
165
|
+
'name' => active_apps.name,
|
166
|
+
'stack' => active_apps.stack,
|
167
|
+
'uid' => active_apps.uid,
|
168
|
+
'app_name' => active_apps.app.name,
|
169
|
+
'app_logo' => active_apps.app.logo
|
170
|
+
})
|
171
|
+
end
|
172
|
+
hash
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module MnoEnterprise
|
2
|
+
|
3
|
+
# Expect user to be defined
|
4
|
+
shared_examples "a navigatable protected user action" do
|
5
|
+
context "with guest user" do
|
6
|
+
before { sign_out(user) }
|
7
|
+
before { subject }
|
8
|
+
it { expect(response).to redirect_to(new_user_session_path) }
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'with signed in and unconfirmed user' do
|
12
|
+
before { allow_any_instance_of(MnoEnterprise::User).to receive(:confirmed?).and_return(false) }
|
13
|
+
before { sign_in user }
|
14
|
+
before { subject }
|
15
|
+
it { expect(response).to redirect_to(user_confirmation_lounge_path) }
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'with signed in and confirmed user' do
|
19
|
+
before { sign_in user }
|
20
|
+
before { subject }
|
21
|
+
it { expect(response.code).to match(/(200|302)/) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
shared_examples "a user protected resource" do
|
26
|
+
context "with guest user" do
|
27
|
+
before { sign_out(user) }
|
28
|
+
before { subject }
|
29
|
+
it { expect(response).to redirect_to(new_user_session_path) }
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'with authorized user' do
|
33
|
+
before { allow(ability).to receive(:can?).with(any_args).and_return(true) }
|
34
|
+
before { sign_in user }
|
35
|
+
before { subject }
|
36
|
+
it { expect(response.code).to match(/20\d|302/) }
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'with unauthorized user' do
|
40
|
+
before { allow(ability).to receive(:can?).with(any_args).and_return(false) }
|
41
|
+
before { sign_in user }
|
42
|
+
before { subject }
|
43
|
+
it { expect(response.code).to match(/(302|401)/) }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# desc "Explaining what the task does"
|
2
|
+
# task :mno_enterprise do
|
3
|
+
# # Task goes here
|
4
|
+
# end
|
5
|
+
|
6
|
+
# /*\ WARNING /*\
|
7
|
+
# Make sure you never screw with that tasks. Ever.
|
8
|
+
# Otherwise, deletion of all database data may occur.
|
9
|
+
#
|
10
|
+
# This task is used by the Ansible automation scripts
|
11
|
+
# to automatically setup/seed the database or migrate it
|
12
|
+
#
|
13
|
+
namespace :db do
|
14
|
+
desc 'Migrate the database or set it up'
|
15
|
+
task :migrate_or_setup => :environment do
|
16
|
+
if ActiveRecord::Migrator.current_version > 0
|
17
|
+
Rake::Task['db:migrate'].invoke
|
18
|
+
else
|
19
|
+
Rake::Task['db:setup'].invoke
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
module MnoEnterprise
|
4
|
+
describe ApplicationController, type: :controller do
|
5
|
+
# Enable CSRF protection for this test
|
6
|
+
before { ActionController::Base.allow_forgery_protection = true }
|
7
|
+
|
8
|
+
# Anonymous controller
|
9
|
+
controller do
|
10
|
+
include MnoEnterprise::Concerns::Controllers::AngularCSRF
|
11
|
+
protect_from_forgery with: :exception
|
12
|
+
|
13
|
+
def index
|
14
|
+
render text: 'Hello World'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'Angular CSRF' do
|
19
|
+
it 'provides the CSRF token to Angular in a cookie' do
|
20
|
+
get :index
|
21
|
+
expect(response.cookies['XSRF-TOKEN']).to be_instance_of(String)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'accepts the CSRF token to be provide via the headers' do
|
25
|
+
get :index
|
26
|
+
request.headers['X-XSRF-TOKEN'] = response.cookies['XSRF-TOKEN']
|
27
|
+
|
28
|
+
post :index
|
29
|
+
expect(response.status).to eq(200)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'cleans up the cookie on InvalidAuthenticityRequest' do
|
33
|
+
post :index
|
34
|
+
expect(response.status).to eq(422)
|
35
|
+
expect(response.cookies['XSRF-TOKEN']).to be_instance_of(String)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Disable CSRF protection for all other tests
|
40
|
+
after { ActionController::Base.allow_forgery_protection = false }
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require "rails_helper"
|
2
|
+
|
3
|
+
describe MandrillClient do
|
4
|
+
subject { MandrillClient }
|
5
|
+
|
6
|
+
describe 'email' do
|
7
|
+
let(:template) { :some_template }
|
8
|
+
let(:from) {{ name: "John", email: 'j@e.com' }}
|
9
|
+
let(:to) {{ name: "John", email: 'j@e.com' }}
|
10
|
+
let(:vars) {{ some: 'var' }}
|
11
|
+
|
12
|
+
it 'sends the right template with the right parameters' do
|
13
|
+
expect(subject).to receive(:send_template).with(template,[],{
|
14
|
+
from_name: from[:name],
|
15
|
+
from_email: from[:email],
|
16
|
+
to: [{email: to[:email], type: :to, name: to[:name]}],
|
17
|
+
global_merge_vars: [{name: vars.keys.first.to_s, content: vars.values.first}]
|
18
|
+
})
|
19
|
+
subject.deliver(template,from,to,vars)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "send_template" do
|
24
|
+
let!(:orig_delivery_method) { Rails.configuration.action_mailer.delivery_method }
|
25
|
+
before { MandrillClient.instance_variable_set("@client",nil) }
|
26
|
+
before { Rails.configuration.action_mailer.delivery_method = :foo_method }
|
27
|
+
after { Rails.configuration.action_mailer.delivery_method = orig_delivery_method }
|
28
|
+
|
29
|
+
it 'delegates the method to a mandrill client' do
|
30
|
+
messages = double('messages')
|
31
|
+
mandrill = double('mandrill', messages: messages)
|
32
|
+
expect(Mandrill::API).to receive(:new).and_return(mandrill)
|
33
|
+
|
34
|
+
args = ['template_name', [], { foo: 'bar' }]
|
35
|
+
expect(messages).to receive(:send_template).with(*args)
|
36
|
+
MandrillClient.send_template(*args)
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'with nil delivery method' do
|
40
|
+
before { Rails.configuration.action_mailer.delivery_method = nil }
|
41
|
+
|
42
|
+
it 'delegates the method to a mandrill client' do
|
43
|
+
messages = double('messages')
|
44
|
+
mandrill = double('mandrill', messages: messages)
|
45
|
+
expect(Mandrill::API).to receive(:new).and_return(mandrill)
|
46
|
+
|
47
|
+
args = ['template_name', [], { foo: 'bar' }]
|
48
|
+
expect(messages).to receive(:send_template).with(*args)
|
49
|
+
MandrillClient.send_template(*args)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe 'with :test delivery method' do
|
54
|
+
before { Rails.configuration.action_mailer.delivery_method = :test }
|
55
|
+
|
56
|
+
it 'does not send any email' do
|
57
|
+
# test no expectation failure
|
58
|
+
allow(Mandrill::API).to receive(:new).and_return(double('mandrill'))
|
59
|
+
MandrillClient.send_template('1',[],{})
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe MnoEnterprise do
|
4
|
+
|
5
|
+
describe 'configure' do
|
6
|
+
it 'yields self' do
|
7
|
+
MnoEnterprise.configure { |config| expect(config).to eq(MnoEnterprise) }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'mnoe_api_v1' do
|
12
|
+
let(:private_host) { nil }
|
13
|
+
subject { MnoEnterprise.mnoe_api_v1.base_uri }
|
14
|
+
before { MnoEnterprise.configure { |c| c.mno_api_private_host = private_host } }
|
15
|
+
|
16
|
+
describe 'without private host' do
|
17
|
+
it { expect(subject).to eq('https://api-enterprise.maestrano.com/v1') }
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'with private host' do
|
21
|
+
let(:private_host) { 'https://api-hub.account.local' }
|
22
|
+
it { expect(subject).to eq("#{private_host}/v1") }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'jwt' do
|
27
|
+
before { MnoEnterprise.configure { |c| c.tenant_id = "12345789"; c.tenant_key = "abcdefg"} }
|
28
|
+
let(:secret) { "#{MnoEnterprise.tenant_id}:#{MnoEnterprise.tenant_key}" }
|
29
|
+
let(:token) { MnoEnterprise.jwt({ user_id: 'someid' }) }
|
30
|
+
subject { HashWithIndifferentAccess.new(JWT.decode(token, secret).first) }
|
31
|
+
|
32
|
+
it 'generates a valid json web token' do
|
33
|
+
expect { subject }.to_not raise_error
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'includes the payload' do
|
37
|
+
expect(subject[:user_id]).to eq('someid')
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'includes an issuer property' do
|
41
|
+
expect(subject[:iss]).to eq(MnoEnterprise.tenant_id)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'includes an issue_at property' do
|
45
|
+
expect(subject[:iat]).to be > 10.seconds.ago.to_i
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'includes a JWT ID property' do
|
49
|
+
expect(subject[:jit]).to eq(Digest::MD5.hexdigest("#{secret}:#{subject[:iat]}"))
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'router' do
|
54
|
+
|
55
|
+
describe 'launch_url' do
|
56
|
+
let(:id) { "cld-1d45e6" }
|
57
|
+
let(:url) { "#{MnoEnterprise.mno_api_host}#{MnoEnterprise.mno_api_root_path}/launch/#{id}" }
|
58
|
+
it { expect(MnoEnterprise.router.launch_url(id)).to eq(url) }
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'authorize_oauth_url' do
|
62
|
+
let(:id) { "cld-1d45e6" }
|
63
|
+
let(:url) { "#{MnoEnterprise.mno_api_host}#{MnoEnterprise.mno_api_root_path}/oauth/#{id}/authorize" }
|
64
|
+
it { expect(MnoEnterprise.router.authorize_oauth_url(id)).to eq(url) }
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'disconnect_oauth_url' do
|
68
|
+
let(:id) { "cld-1d45e6" }
|
69
|
+
let(:url) { "#{MnoEnterprise.mno_api_host}#{MnoEnterprise.mno_api_root_path}/oauth/#{id}/disconnect" }
|
70
|
+
it { expect(MnoEnterprise.router.disconnect_oauth_url(id)).to eq(url) }
|
71
|
+
end
|
72
|
+
|
73
|
+
describe 'sync_oauth_url' do
|
74
|
+
let(:id) { "cld-1d45e6" }
|
75
|
+
let(:url) { "#{MnoEnterprise.mno_api_host}#{MnoEnterprise.mno_api_root_path}/oauth/#{id}/sync" }
|
76
|
+
it { expect(MnoEnterprise.router.sync_oauth_url(id)).to eq(url) }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|