Skip to content

Commit

Permalink
adding checks for mandatory elements of attributes.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
kakwa committed May 17, 2015
1 parent dbc8816 commit 679c2bb
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 11 deletions.
4 changes: 3 additions & 1 deletion conf/attributes.yml
Expand Up @@ -96,14 +96,16 @@ home:
ad: Home

password:
decription: "Password of the user"
description: "Password of the user"
display_name: "Password"
self: True
type: password
backend-attributes:
ldap: userPassword
ad: userPassword
logscript:
description: "Windows login script"
display_name: "Login script"
type: fix
value: login1.bat
backend-attributes:
Expand Down
10 changes: 9 additions & 1 deletion ldapcherry/attributes.py
Expand Up @@ -10,7 +10,7 @@

from ldapcherry.pyyamlwrapper import loadNoDump
from ldapcherry.pyyamlwrapper import DumplicatedKey
from ldapcherry.exceptions import MissingAttributesFile
from ldapcherry.exceptions import MissingAttributesFile, MissingKey
from sets import Set
import yaml

Expand All @@ -30,6 +30,14 @@ def __init__(self, attributes_file):
except DumplicatedKey as e:
raise DumplicateAttributesKey(e.key)

for attrid in self.attributes:
self._mandatory_check(attrid)

def _mandatory_check(self, attr):
for m in ['description', 'display_name', 'type', 'backend-attributes']:
if m not in self.attributes[attr]:
raise MissingKey(m, attr, self.attributes_file)

def get_selfattributes(self):
"""get the list of groups from roles"""
pass
Expand Down
111 changes: 111 additions & 0 deletions tests/cfg/attributes_missing_mandatory.yml
@@ -0,0 +1,111 @@
cn:
description: "Firt Name and Display Name"
display_name: "Display Name"
type: string
autofill:
function: cn
args:
- $first-name
- $name
backend-attributes:
ldap: cn
ad: CN
first-name:
description: "First name of the user"
display_name: "First Name"
type: string
backend-attributes:
ldap: givenName
ad: givenName
name:
description: "Family name of the user"
display_name: "Name"
type: string
backend-attributes:
ldap: sn
ad: sn
email:
description: "Email of the user"
display_name: "Name"
type: email
autofill:
function: email
args:
- $first-name
- $last-name
- '@example.com'
backend-attributes:
ldap: email
ad: EMAIL
uid:
display_name: "UID"
type: string
autofill:
function: uid
args:
- $first-name
- $last-name
backend-attributes:
ldap: uid
ad: UID
uidNumber:
description: "User ID Number of the user"
display_name: "UID Number"
type: int
autofill:
function: uidNumber
args:
- $first-name
- $last-name
backend-attributes:
ldap: uidNumber
ad: UIDNumber
gidNumber:
description: "Group ID Number of the user"
display_name: "GID Number"
type: int
default: 10000
backend-attributes:
ldap: gidNumber
ad: GIDNumber
shell:
description: "Shell of the user"
display_name: "Shell"
self: True
type: stringlist
values:
- /bin/bash
- /bin/zsh
- /bin/sh
backend-attributes:
ldap: shell
ad: SHELL
home:
description: "Home user path"
display_name: "Home"
type: string
autofill:
function: home
args:
- $first-name
- $last-name
- /home/
backend-attributes:
ldap: home
ad: Home

password:
description: "Password of the user"
display_name: "Password"
self: True
type: password
backend-attributes:
ldap: userPassword
ad: userPassword
logscript:
description: "Windows login script"
display_name: "Login script"
type: fix
value: login1.bat
backend-attributes:
ad: logonScript
18 changes: 9 additions & 9 deletions tests/test_Attributes.py
Expand Up @@ -8,7 +8,7 @@
import sys
from sets import Set
from ldapcherry.attributes import Attributes
from ldapcherry.exceptions import MissingAttributesFile
from ldapcherry.exceptions import MissingAttributesFile, MissingKey
from ldapcherry.pyyamlwrapper import DumplicatedKey, RelationError

class TestError(object):
Expand All @@ -25,14 +25,14 @@ def testNoFile(self):
else:
raise AssertionError("expected an exception")

# def testMissingDisplayName(self):
# try:
# inv = Attributes('./tests/cfg/attributes_missing_diplay_name.yml')
# except MissingKey:
# return
# else:
# raise AssertionError("expected an exception")
#
def testMissingMandatory(self):
try:
inv = Attributes('./tests/cfg/attributes_missing_mandatory.yml')
except MissingKey:
return
else:
raise AssertionError("expected an exception")

# def testAttrKeyDuplication(self):
# try:
# inv = Attributes('./tests/cfg/attributes_key_dup.yml')
Expand Down

0 comments on commit 679c2bb

Please sign in to comment.