summaryrefslogtreecommitdiff
path: root/users/test/unit/token_test.rb
blob: bff6b71c5d2401bdfda5c6e7b82e10204b05f781 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require 'test_helper'

class ClientCertificateTest < ActiveSupport::TestCase

  setup do
    @user = FactoryGirl.create(:user)
  end

  teardown do
    @user.destroy
  end

  test "new token for user" do
    sample = Token.new(:user_id => @user.id)
    assert sample.valid?
    assert_equal @user.id, sample.user_id
  end

  test "token id is secure" do
    sample = Token.new(:user_id => @user.id)
    other = Token.new(:user_id => @user.id)
    assert sample.id,
      "id is set on initialization"
    assert sample.id[0..10] != other.id[0..10],
      "token id prefixes should not repeat"
    assert /[g-zG-Z]/.match(sample.id),
      "should use non hex chars in the token id"
    assert sample.id.size > 16,
      "token id should be more than 16 chars long"
  end

  test "token checks for user" do
    sample = Token.new
    assert !sample.valid?, "Token should require a user record"
  end

end