liquid_feedback_frontend

diff env/ldap/test.lua @ 1071:58f48a8a202a

Imported and merged LDAP patch
author bsw
date Fri Jul 18 21:42:59 2014 +0200 (2014-07-18)
parents
children aefef1556d55
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/env/ldap/test.lua	Fri Jul 18 21:42:59 2014 +0200
     1.3 @@ -0,0 +1,141 @@
     1.4 +-- Part of test case for ldap4lqfb
     1.5 +
     1.6 +function ldap.test()
     1.7 +
     1.8 +  local global_count = 0
     1.9 +  local global_failed = 0
    1.10 +  
    1.11 +  local function checkMember(uid, login, name, units_with_voting_priv, units_with_polling_priv)
    1.12 +
    1.13 +    local failed = false
    1.14 +    
    1.15 +    local function testError(err, expected, got)
    1.16 +      failed = true
    1.17 +      global_failed = global_failed + 1
    1.18 +      if expected then
    1.19 +        print ("[" .. uid .. "] FAILED: " .. err .. " (expected: '" .. expected .. "' but got '" .. tostring(got) .. "')") 
    1.20 +      else
    1.21 +        print ("[" .. uid .. "] FAILED: " .. err)
    1.22 +      end
    1.23 +    end
    1.24 +
    1.25 +    local function testOk(test, expected)
    1.26 +      if test then
    1.27 +        print ("[" .. uid .. "] " .. test .. " ok ('" .. expected .. "')")
    1.28 +      else
    1.29 +        print ("[" .. uid .. "] success")
    1.30 +      end
    1.31 +    end
    1.32 +    
    1.33 +    local function test(field, expected, value)
    1.34 +      global_count = global_count + 1
    1.35 +      if expected ~= value then
    1.36 +        testError(field, expected, value)
    1.37 +        return
    1.38 +      end
    1.39 +      testOk(field, expected)
    1.40 +    end
    1.41 +    
    1.42 +    local members = Member:new_selector()
    1.43 +      :add_field{ "authority_data->'login' as authority_data_login" }
    1.44 +      :add_where{ "authority = ? AND authority_data->'uid' = ?", "ldap", uid }
    1.45 +      :exec()
    1.46 +
    1.47 +    if #members < 1 then
    1.48 +      testError("Member not found in DB")
    1.49 +      return
    1.50 +    end
    1.51 +    
    1.52 +    if #members > 1 then
    1.53 +      testError("Found more than one DB entry")
    1.54 +      return
    1.55 +    end
    1.56 +    
    1.57 +    local member = members[1]
    1.58 +    
    1.59 +    if login == nil then
    1.60 +      if not member.locked then
    1.61 +        testError("Member not locked")
    1.62 +      else
    1.63 +        testOk("Member is locked", "true")
    1.64 +      end
    1.65 +      return
    1.66 +    end
    1.67 +      
    1.68 +    test("login", login, member.authority_data_login)
    1.69 +    test("name", name, member.name)
    1.70 +    
    1.71 +    for i, unit_id in ipairs(units_with_voting_priv) do
    1.72 +      global_count = global_count + 1
    1.73 +      local privilege = Privilege:by_pk(unit_id, member.id)
    1.74 +      if privilege and privilege.voting_right then
    1.75 +        testOk("voting_right", unit_id)
    1.76 +      else
    1.77 +        testError("voting_right", unit_id, "")
    1.78 +      end
    1.79 +    end
    1.80 +    
    1.81 +    local privileges_selector = Privilege:new_selector()
    1.82 +      :add_where{ "member_id = ?", member.id }
    1.83 +      :add_where("voting_right = true")
    1.84 +    if #units_with_voting_priv > 0 then
    1.85 +      local privileges = privileges_selector:add_where{ "unit_id NOT IN ($)", units_with_voting_priv }
    1.86 +    end
    1.87 +    local privileges = privileges_selector:exec()
    1.88 +      
    1.89 +    if #privileges > 0 then
    1.90 +      testError("voting_right", "count: 0", "count: " .. #privileges)
    1.91 +    else
    1.92 +      testOk("voting_right", "count: 0")
    1.93 +    end
    1.94 +    
    1.95 +    for i, unit_id in ipairs(units_with_polling_priv) do
    1.96 +      global_count = global_count + 1
    1.97 +      local privilege = Privilege:by_pk(unit_id, member.id)
    1.98 +      if privilege and privilege.polling_right then
    1.99 +        testOk("polling_right", unit_id)
   1.100 +      else
   1.101 +        testError("polling_right", unit_id, "")
   1.102 +      end
   1.103 +    end
   1.104 +    
   1.105 +    local privileges_selector = Privilege:new_selector()
   1.106 +      :add_where{ "member_id = ?", member.id }
   1.107 +      :add_where("polling_right = true")
   1.108 +    if #units_with_polling_priv > 0 then
   1.109 +      privileges_selector:add_where{ "unit_id NOT IN ($)", units_with_polling_priv }
   1.110 +    end
   1.111 +    local privileges = privileges_selector:exec()
   1.112 +      
   1.113 +    if #privileges > 0 then
   1.114 +      testError("polling_right", "count: " .. #units_with_polling_priv, "count: " .. #privileges)
   1.115 +    else
   1.116 +      testOk("polling_right", "count: " .. #units_with_polling_priv)
   1.117 +    end
   1.118 +    
   1.119 +    if not failed then
   1.120 +      return true
   1.121 +    end
   1.122 +    
   1.123 +    return false
   1.124 +    
   1.125 +  end
   1.126 +  
   1.127 +  checkMember("1000", "alice", "Alice Amberg", { 1 }, { })
   1.128 +  checkMember("1001", "bob", "Bob Bobbersen", { 1, 2 }, { 1, 3 })
   1.129 +  checkMember("1002", "chris", "Chris Carv", { 1, 2 }, { 1, 3 })
   1.130 +  checkMember("1003", "daisy", "Daisy Duck", { 3 }, { 1, 2 })
   1.131 +  checkMember("1004", "ernst", "Ernst Ernst", { 3 }, { 1, 2 })
   1.132 +  checkMember("1005", "fredi", "Frederike Frei", { 1 }, { })
   1.133 +  checkMember("1006")
   1.134 +  checkMember("1007", "helen", "Helen Hofstatter", { 1, 2 }, { 1, 3 })
   1.135 +  checkMember("1008", "iwan", "Iwan Iwanowski", { 1 }, { })
   1.136 +  checkMember("1009", "jasmina", "Jasmina Jasik", { 1 }, { })
   1.137 +
   1.138 +  print()
   1.139 +  
   1.140 +  local success_count = global_count - global_failed
   1.141 +  
   1.142 +  print (success_count .. " of " .. global_count .. " tests succeeded.")
   1.143 + 
   1.144 +end

Impressum / About Us