Project

General

Profile

Revision 9ea40591

Added by Daniel Lobato Garcia over 6 years ago

Fixes #14181 - Validate registry URL and attempt login

In order to avoid users trying to create containers in an external
registry that doesn't exist, we should provide some preventative
measures.

View differences:

test/units/docker_registry_test.rb
24 24
    assert registry.is_decryptable?(registry.password_in_db)
25 25
  end
26 26

  
27
  %w(name url).each do |property|
28
    test "registries need a #{property}" do
29
      refute FactoryGirl.build(:docker_registry, property.to_sym => '').valid?
27
  should validate_presence_of(:name)
28
  should validate_presence_of(:url)
29
  should validate_uniqueness_of(:name)
30
  should validate_uniqueness_of(:url)
31

  
32
  context 'attempt to login' do
33
    setup do
34
      @registry = FactoryGirl.build(:docker_registry)
35
      @registry.unstub(:attempt_login)
36
    end
37

  
38
    test 'before creating a registry' do
39
      ::Docker.expects(:authenticate!)
40
      assert @registry.valid?
41
    end
42

  
43
    test 'display errors in case authentication failed' do
44
      ::Docker.expects(:authenticate!).
45
        raises(Docker::Error::AuthenticationError)
46
      refute @registry.valid?
30 47
    end
31 48
  end
32 49
end

Also available in: Unified diff