Skip to content

Commit 7c01457

Browse files
committed
Remove external lib method get_ext_lib_path. Add set_cert_path in order to allow set the cert path in a different folder than the toolkit
1 parent f904996 commit 7c01457

File tree

2 files changed

+45
-21
lines changed

2 files changed

+45
-21
lines changed

src/onelogin/saml2/settings.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ def __load_paths(self, base_path=None):
143143
self.__paths = {
144144
'base': base_path,
145145
'cert': base_path + 'certs' + sep,
146-
'lib': base_path + 'lib' + sep,
147-
'extlib': base_path + 'extlib' + sep,
146+
'lib': dirname(__file__) + sep
148147
}
149148

150149
def __update_paths(self, settings):
@@ -168,6 +167,12 @@ def get_base_path(self):
168167
"""
169168
return self.__paths['base']
170169

170+
def set_cert_path(self, path):
171+
"""
172+
Set a new cert path
173+
"""
174+
self.__paths['cert'] = path
175+
171176
def get_cert_path(self):
172177
"""
173178
Returns cert path
@@ -186,15 +191,6 @@ def get_lib_path(self):
186191
"""
187192
return self.__paths['lib']
188193

189-
def get_ext_lib_path(self):
190-
"""
191-
Returns external lib path
192-
193-
:return: The external library folder path
194-
:rtype: string
195-
"""
196-
return self.__paths['extlib']
197-
198194
def get_schemas_path(self):
199195
"""
200196
Returns schema path

tests/src/OneLogin/saml2_tests/settings_test.py

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,29 +125,57 @@ def testGetCertPath(self):
125125
settings = OneLogin_Saml2_Settings(custom_base_path=self.settings_path)
126126
self.assertEqual(self.settings_path + sep + 'certs' + sep, settings.get_cert_path())
127127

128-
def testGetLibPath(self):
128+
def testSetCertPath(self):
129129
"""
130-
Tests getLibPath method of the OneLogin_Saml2_Settings
130+
Tests setCertPath method of the OneLogin_Saml2_Settings
131131
"""
132132
settings = OneLogin_Saml2_Settings(custom_base_path=self.settings_path)
133-
base = settings.get_base_path()
134-
self.assertEqual(join(base, 'lib') + sep, settings.get_lib_path())
133+
self.assertEqual(self.settings_path + sep + 'certs' + sep, settings.get_cert_path())
135134

136-
def testGetExtLibPath(self):
135+
settings.set_cert_path('/tmp')
136+
self.assertEqual('/tmp', settings.get_cert_path())
137+
138+
def testGetLibPath(self):
137139
"""
138-
Tests getExtLibPath method of the OneLogin_Saml2_Settings
140+
Tests getLibPath method of the OneLogin_Saml2_Settings
139141
"""
142+
settingsInfo = self.loadSettingsJSON()
143+
settings = OneLogin_Saml2_Settings(settingsInfo)
144+
path = settings.get_base_path()
145+
self.assertEqual(settings.get_lib_path(), join(dirname(dirname(dirname(dirname(dirname(__file__))))), 'src/onelogin/saml2/'))
146+
self.assertEqual(path, join(dirname(dirname(dirname(dirname(dirname(__file__))))), 'src/onelogin/saml2/../../../tests/data/customPath/'))
147+
148+
del settingsInfo['custom_base_path']
149+
settings = OneLogin_Saml2_Settings(settingsInfo)
150+
path = settings.get_base_path()
151+
self.assertEqual(settings.get_lib_path(), join(dirname(dirname(dirname(dirname(dirname(__file__))))), 'src/onelogin/saml2/'))
152+
self.assertEqual(path, join(dirname(dirname(dirname(dirname(dirname(__file__))))), 'src/'))
153+
140154
settings = OneLogin_Saml2_Settings(custom_base_path=self.settings_path)
141-
base = settings.get_base_path()
142-
self.assertEqual(join(base, 'extlib') + sep, settings.get_ext_lib_path())
155+
path = settings.get_base_path()
156+
self.assertEqual(settings.get_lib_path(), join(dirname(dirname(dirname(dirname(dirname(__file__))))), 'src/onelogin/saml2/'))
157+
self.assertEqual(path, join(dirname(dirname(dirname(dirname(__file__)))), 'settings/'))
143158

144159
def testGetSchemasPath(self):
145160
"""
146161
Tests getSchemasPath method of the OneLogin_Saml2_Settings
147162
"""
163+
settingsInfo = self.loadSettingsJSON()
164+
settings = OneLogin_Saml2_Settings(settingsInfo)
165+
path = settings.get_base_path()
166+
self.assertEqual(settings.get_schemas_path(), join(dirname(dirname(dirname(dirname(dirname(__file__))))), 'src/onelogin/saml2/schemas/'))
167+
self.assertEqual(path, join(dirname(dirname(dirname(dirname(dirname(__file__))))), 'src/onelogin/saml2/../../../tests/data/customPath/'))
168+
169+
del settingsInfo['custom_base_path']
170+
settings = OneLogin_Saml2_Settings(settingsInfo)
171+
path = settings.get_base_path()
172+
self.assertEqual(settings.get_schemas_path(), join(dirname(dirname(dirname(dirname(dirname(__file__))))), 'src/onelogin/saml2/schemas/'))
173+
self.assertEqual(path, join(dirname(dirname(dirname(dirname(dirname(__file__))))), 'src/'))
174+
148175
settings = OneLogin_Saml2_Settings(custom_base_path=self.settings_path)
149-
base = settings.get_base_path()
150-
self.assertEqual(join(base, 'lib', 'schemas') + sep, settings.get_schemas_path())
176+
path = settings.get_base_path()
177+
self.assertEqual(settings.get_schemas_path(), join(dirname(dirname(dirname(dirname(dirname(__file__))))), 'src/onelogin/saml2/schemas/'))
178+
self.assertEqual(path, join(dirname(dirname(dirname(dirname(__file__)))), 'settings/'))
151179

152180
def testGetIdPSSOurl(self):
153181
"""

0 commit comments

Comments
 (0)