-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
60 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
module Services | ||
class DomainOwnershipService | ||
|
||
def initialize | ||
end | ||
|
||
def get_domain_info | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
class Domain < ApplicationRecord | ||
serialize :groups, :users, coder: YAML, type: Array | ||
before_save :clean_users_groups | ||
|
||
validates :fqdn, presence: true | ||
|
||
def clean_users_groups | ||
self.groups = groups.sort.uniq | ||
self.users = users.sort.uniq | ||
def groups_array | ||
(groups || "").split(",").sort.uniq | ||
end | ||
|
||
def users_array | ||
(users || "").split(",").sort.uniq | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,5 @@ | |
|
||
# this seed is for development only | ||
if Rails.env.development? | ||
Domain.first_or_create!(fqdn: "example.com", owner: "[email protected]") | ||
Domain.first_or_create!(fqdn: "example.com", users: "[email protected]") | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
owner_match: | ||
fqdn: example.com | ||
owner: [email protected] | ||
users: [email protected] | ||
group_delegation: false | ||
|
||
group_match: | ||
fqdn: example2.com | ||
owner: [email protected] | ||
users: [email protected] | ||
group_delegation: true | ||
groups: | ||
- "group1" | ||
groups: group1 | ||
|
||
no_match: | ||
fqdn: example3.com | ||
owner: [email protected] | ||
users: [email protected] | ||
group_delegation: true | ||
groups: | ||
- "group3" | ||
groups: group3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,31 +3,35 @@ | |
class AuthorizeRequestTest < ActiveSupport::TestCase | ||
def setup | ||
@domain = domains(:group_match) | ||
@identity = Identity.new(subject: @domain.owner) | ||
@identity = Identity.new(subject: @domain.users_array.first) | ||
@cr = CertIssueRequest.new(common_name: @domain.fqdn) | ||
@interactor = AuthorizeRequest | ||
end | ||
|
||
test "successful call" do | ||
request = CertIssueRequest.new(common_name: @domain.fqdn) | ||
srv = Minitest::Mock.new | ||
srv.expect :authorize!, nil, [ @identity, @cr ] | ||
Services::DomainOwnershipService.stub :new, srv do | ||
context = @interactor.call(identity: @identity, request: @cr) | ||
assert context.success? | ||
end | ||
test ".call with matching owner" do | ||
rslt = @interactor.call(identity: @identity, request: @cr) | ||
assert rslt.success? | ||
end | ||
|
||
test "unsuccessful call" do | ||
request = CertIssueRequest.new(common_name: @domain.fqdn) | ||
srv = Services::DomainOwnershipService.new | ||
Services::DomainOwnershipService.stub :new, srv do | ||
err = ->(_, _) { raise AuthError.new "no can do" } | ||
srv.stub :authorize!, err do | ||
context = @interactor.call(identity: @identity, request: @cr) | ||
assert_not context.success? | ||
assert_kind_of AuthError, context.error | ||
end | ||
end | ||
test ".call with non-matching owner" do | ||
@identity.subject = "[email protected]" | ||
rslt = @interactor.call(identity: @identity, request: @cr) | ||
assert_not rslt.success? | ||
assert_kind_of AuthError, rslt.error | ||
end | ||
|
||
test ".call with matching group" do | ||
@domain.update(users: "[email protected]") | ||
@identity.groups = @domain.groups_array | ||
rslt = @interactor.call(identity: @identity, request: @cr) | ||
assert rslt.success? | ||
end | ||
|
||
test ".call with non-matching group" do | ||
@domain.update(users: "[email protected]") | ||
@identity.groups = [ "different_group" ] | ||
rslt = @interactor.call(identity: @identity, request: @cr) | ||
assert_not rslt.success? | ||
assert_kind_of AuthError, rslt.error | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,4 @@ | ||
require "test_helper" | ||
|
||
class DomainOwnershipServiceTest < ActiveSupport::TestCase | ||
def setup | ||
@domain = domains(:group_match) | ||
@identity = Identity.new(subject: @domain.owner) | ||
@cr = CertIssueRequest.new(common_name: @domain.fqdn) | ||
@ds = Services::DomainOwnershipService.new | ||
end | ||
|
||
test "#authorize! with matching owner" do | ||
assert_nil(@ds.authorize!(@identity, @cr)) | ||
end | ||
|
||
test "#authorize! with non-matching owner" do | ||
@identity.subject = "[email protected]" | ||
assert_raises(AuthError) do | ||
@ds.authorize!(@identity, @cr) | ||
end | ||
end | ||
|
||
test "#authorize! with matching group" do | ||
@domain.update(owner: "[email protected]") | ||
@identity.groups = @domain.groups | ||
assert_nil(@ds.authorize!(@identity, @cr)) | ||
end | ||
|
||
test "#authorize! with non-matching group" do | ||
@domain.update(owner: "[email protected]") | ||
@identity.groups = [ "different_group" ] | ||
assert_raises(AuthError) do | ||
@ds.authorize!(@identity, @cr) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ class DomainTest < ActiveSupport::TestCase | |
def setup | ||
@attributes = { | ||
fqdn: "example4.com", | ||
owner: "[email protected]" | ||
users: "[email protected]" | ||
} | ||
@domain = Domain.new(@attributes) | ||
end | ||
|
@@ -26,15 +26,13 @@ def setup | |
assert_includes @domain.errors[:fqdn], "can't be blank" | ||
end | ||
|
||
test "#valid? should require an owner" do | ||
@domain.owner = nil | ||
assert_not @domain.valid? | ||
assert_includes @domain.errors[:owner], "can't be blank" | ||
test "#groups_array should sort dedupe groups" do | ||
@domain.groups = "two,two,one" | ||
assert_equal [ "one", "two" ], @domain.groups_array | ||
end | ||
|
||
test "before_save should sort and dedupe groups" do | ||
@domain.groups = [ "two", "two", "one" ] | ||
@domain.save | ||
assert_equal [ "one", "two" ], @domain.groups | ||
test "#users_array should sort dedupe users" do | ||
@domain.users = "two,two,one" | ||
assert_equal [ "one", "two" ], @domain.users_array | ||
end | ||
end |