Skip to content

Commit

Permalink
refactor: Content -> Authentication
Browse files Browse the repository at this point in the history
It is the tickets content but more precisely its an Authentication Record.
Now auth.expired? and auth.service make a lot more sense than before.
  • Loading branch information
azul committed Jan 13, 2017
1 parent b0d1bf5 commit a3335db
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 38 deletions.
2 changes: 1 addition & 1 deletion lib/rbsso/content.rb → lib/rbsso/authentication.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module RbSSO
class Content
class Authentication
VERSION = 3

class VersionMismatch < ArgumentError
Expand Down
4 changes: 2 additions & 2 deletions lib/rbsso/client.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rbnacl'
require 'rbsso/ticket'
require 'rbsso/content'
require 'rbsso/authentication'

module RbSSO
class Client
Expand All @@ -27,7 +27,7 @@ def initialize(service, key)

def open(ticket_string)
ticket = RbSSO::Ticket.open ticket_string, verify_key
auth = RbSSO::Content.parse ticket.content
auth = RbSSO::Authentication.parse ticket.content
raise TicketExpired.new(auth.expires) if auth.expired?
raise WrongService.new(service, auth.service) if auth.service != service
auth.to_info
Expand Down
8 changes: 5 additions & 3 deletions lib/rbsso/server.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rbnacl'
require 'rbsso/ticket'
require 'rbsso/content'
require 'rbsso/authentication'

module RbSSO
class Server
Expand All @@ -14,8 +14,10 @@ def initialize(secret)
end

def ticket(user, service, domain)
content = RbSSO::Content.new user: user, service: service, domain: domain
ticket = RbSSO::Ticket.sign content, key
auth = RbSSO::Authentication.new user: user,
service: service,
domain: domain
ticket = RbSSO::Ticket.sign auth, key
return ticket.to_base64
end

Expand Down
32 changes: 32 additions & 0 deletions test/rbsso/authentication.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'test_helper'
require 'rbsso/authentication'

class RbSSO::AuthenticationTest < Minitest::Test

def test_basic_attributes
assert_equal 'user', auth.user
assert_equal 'service', auth.service
assert_equal 'domain', auth.domain
end

def test_to_s
assert_match /^3|user|service|domain|\d*|$/, auth.to_s
end

def test_parse
parsed = RbSSO::Authentication.parse auth.to_s
assert_equal auth, parsed
end

def test_invalid_version
assert_raises RbSSO::Authentication::VersionMismatch do
RbSSO::Authentication.parse '4|other versions may contain other auth'
end
end

def auth
RbSSO::Authentication.new user: 'user',
service: 'service',
domain: 'domain'
end
end
32 changes: 0 additions & 32 deletions test/rbsso/content_test.rb

This file was deleted.

0 comments on commit a3335db

Please sign in to comment.