Class: MockServer::Jwt

Inherits:
Object
  • Object
show all
Defined in:
lib/mockserver/models.rb

Overview

JWT (bearer-token) request matcher. Matches a request whose JWT — carried by default in the Authorization: Bearer <token> header — satisfies every constraint below.

claims is a { claim-name => value } map where each value is an exact string or a regular expression; a leading ! negates the match (the NottableString convention shared across MockServer matchers). issuer, audience, algorithm, header and scheme are optional; unset keys are omitted.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(claims: nil, issuer: nil, audience: nil, algorithm: nil, header: nil, scheme: nil) ⇒ Jwt

Returns a new instance of Jwt.



740
741
742
743
744
745
746
747
# File 'lib/mockserver/models.rb', line 740

def initialize(claims: nil, issuer: nil, audience: nil, algorithm: nil, header: nil, scheme: nil)
  @claims = claims
  @issuer = issuer
  @audience = audience
  @algorithm = algorithm
  @header = header
  @scheme = scheme
end

Instance Attribute Details

#algorithmObject

Returns the value of attribute algorithm.



738
739
740
# File 'lib/mockserver/models.rb', line 738

def algorithm
  @algorithm
end

#audienceObject

Returns the value of attribute audience.



738
739
740
# File 'lib/mockserver/models.rb', line 738

def audience
  @audience
end

#claimsObject

Returns the value of attribute claims.



738
739
740
# File 'lib/mockserver/models.rb', line 738

def claims
  @claims
end

#headerObject

Returns the value of attribute header.



738
739
740
# File 'lib/mockserver/models.rb', line 738

def header
  @header
end

#issuerObject

Returns the value of attribute issuer.



738
739
740
# File 'lib/mockserver/models.rb', line 738

def issuer
  @issuer
end

#schemeObject

Returns the value of attribute scheme.



738
739
740
# File 'lib/mockserver/models.rb', line 738

def scheme
  @scheme
end

Class Method Details

.from_hash(data) ⇒ Object



760
761
762
763
764
765
766
767
768
769
770
771
# File 'lib/mockserver/models.rb', line 760

def self.from_hash(data)
  return nil if data.nil?

  new(
    claims:    data['claims'],
    issuer:    data['issuer'],
    audience:  data['audience'],
    algorithm: data['algorithm'],
    header:    data['header'],
    scheme:    data['scheme']
  )
end

Instance Method Details

#to_hObject



749
750
751
752
753
754
755
756
757
758
# File 'lib/mockserver/models.rb', line 749

def to_h
  result = {}
  result['claims']    = @claims    unless @claims.nil?
  result['issuer']    = @issuer    unless @issuer.nil?
  result['audience']  = @audience  unless @audience.nil?
  result['algorithm'] = @algorithm unless @algorithm.nil?
  result['header']    = @header    unless @header.nil?
  result['scheme']    = @scheme    unless @scheme.nil?
  result
end

#with_claim(name, value) ⇒ Object



773
774
775
776
777
# File 'lib/mockserver/models.rb', line 773

def with_claim(name, value)
  @claims ||= {}
  @claims[name] = value
  self
end