Class: TentValidator::Spec

Inherits:
ApiValidator::Spec
  • Object
show all
Defined in:
lib/tent-validator/spec.rb

Direct Known Subclasses

PostValidator

Instance Method Summary collapse

Instance Method Details

#clients(type, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/tent-validator/spec.rb', line 6

def clients(type, options = {})
  server = options.delete(:server) || :remote
  if server == :remote
    TentClient.new(TentValidator.remote_entity_uri, auth_details_for_app_type(type, options).merge(
      :faraday_adapter => TentValidator.remote_adapter,
      :server_meta => TentValidator.remote_server_meta
    ))
  else
  end
end

#generate_version_signature(post) ⇒ Object



17
18
19
20
# File 'lib/tent-validator/spec.rb', line 17

def generate_version_signature(post)
  canonical_post_json = TentCanonicalJson.encode(post)
  hex_digest(canonical_post_json)
end

#hex_digest(data) ⇒ Object



22
23
24
# File 'lib/tent-validator/spec.rb', line 22

def hex_digest(data)
  Digest::SHA512.new.update(data).to_s[0...64]
end

#invalid_value(type, format = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/tent-validator/spec.rb', line 26

def invalid_value(type, format = nil)
  case type
  when "array"
    Hash.new
  when "boolean"
    "false"
  when "number", "integer"
    "123"
  when "null"
    true
  when "object"
    ["My parent should be an object!"]
  when "string"
    if format
      case format
      when 'uri'
        "I'm not a uri!"
      end
    else
      421
    end
  end
end

#valid_value(type, format = nil) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/tent-validator/spec.rb', line 50

def valid_value(type, format = nil)
  case type
  when "array"
    []
  when "boolean"
    true
  when "number", "integer"
    123
  when "null"
    nil
  when "object"
    Hash.new
  when "string"
    if format
      case format
      when 'uri'
        "https://example.com"
      end
    else
      ""
    end
  end
end