File: test_lpasswd.rb

package info (click to toggle)
ruby-activeldap 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 1,588 kB
  • sloc: ruby: 18,143; sh: 12; makefile: 5
file content (75 lines) | stat: -rw-r--r-- 2,265 bytes parent folder | download | duplicates (6)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require 'al-test-utils'

class TestLPasswd < Test::Unit::TestCase
  include AlTestUtils

  def setup
    super
    @command = File.join(@examples_dir, "lpasswd")
    make_ou("People")
    @user_class.prefix = "ou=People"
  end

  priority :must

  priority :normal
  def test_non_exist_user
    ensure_delete_user("test-user") do |uid,|
      assert(!@user_class.exists?(uid))
      assert_equal([false, "User #{uid} doesn't exist.\n"], run_command(uid))
      assert(!@user_class.exists?(uid))
    end
  end

  def test_change_password
    make_temporary_user do |user, password|
      new_password = "new#{password}"
      assert_lpasswd_successfully(user.uid, password, new_password)
    end
  end

  def test_password_mismatch
    make_temporary_user do |user, password|
      message = "[#{user.dn}] Password: \n" * 2
      message = "#{message}Password mismatch!\n" * 3
      assert_lpasswd_failed(user.id, password, message) do |input, output|
        3.times do
          output.puts("new#{password}1")
          output.puts("new#{password}2")
          output.flush
        end
      end
    end
  end

  private
  def assert_lpasswd_successfully(name, current, new, *args, &block)
    _wrap_assertion do
      assert(@user_class.exists?(name))
      assert_send([ActiveLdap::UserPassword, :valid?,
                   current, @user_class.find(name).user_password])
      args.concat([name])
      block ||=  Proc.new do |input, output|
        output.puts(new)
        output.puts(new)
        output.flush
      end
      assert_equal([true, "[#{@user_class.find(name).dn}] Password: \n" * 2],
                   run_command(*args, &block))
      assert_send([ActiveLdap::UserPassword, :valid?,
                   new, @user_class.find(name).user_password])
    end
  end

  def assert_lpasswd_failed(name, current, message, *args, &block)
    _wrap_assertion do
      assert(@user_class.exists?(name))
      assert_send([ActiveLdap::UserPassword, :valid?,
                   current, @user_class.find(name).user_password])
      args.concat([name])
      assert_equal([false, message], run_command(*args, &block))
      assert_send([ActiveLdap::UserPassword, :valid?,
                   current, @user_class.find(name).user_password])
    end
  end
end