Skip to content

Commit f1e4af2

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 8c828e3 commit f1e4af2

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
@@ -153,8 +153,7 @@ def __load_paths(self, base_path=None):
153153
self.__paths = {
154154
'base': base_path,
155155
'cert': base_path + 'certs' + sep,
156-
'lib': base_path + 'lib' + sep,
157-
'extlib': base_path + 'extlib' + sep,
156+
'lib': dirname(__file__) + sep
158157
}
159158

160159
def __update_paths(self, settings):
@@ -187,6 +186,12 @@ def get_cert_path(self):
187186
"""
188187
return self.__paths['cert']
189188

189+
def set_cert_path(self, path):
190+
"""
191+
Set a new cert path
192+
"""
193+
self.__paths['cert'] = path
194+
190195
def get_lib_path(self):
191196
"""
192197
Returns lib path
@@ -196,15 +201,6 @@ def get_lib_path(self):
196201
"""
197202
return self.__paths['lib']
198203

199-
def get_ext_lib_path(self):
200-
"""
201-
Returns external lib path
202-
203-
:return: The external library folder path
204-
:rtype: string
205-
"""
206-
return self.__paths['extlib']
207-
208204
def get_schemas_path(self):
209205
"""
210206
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
@@ -148,29 +148,57 @@ def testGetCertPath(self):
148148
settings = OneLogin_Saml2_Settings(custom_base_path=self.settings_path)
149149
self.assertEqual(self.settings_path + sep + 'certs' + sep, settings.get_cert_path())
150150

151-
def testGetLibPath(self):
151+
def testSetCertPath(self):
152152
"""
153-
Tests getLibPath method of the OneLogin_Saml2_Settings
153+
Tests setCertPath method of the OneLogin_Saml2_Settings
154154
"""
155155
settings = OneLogin_Saml2_Settings(custom_base_path=self.settings_path)
156-
base = settings.get_base_path()
157-
self.assertEqual(join(base, 'lib') + sep, settings.get_lib_path())
156+
self.assertEqual(self.settings_path + sep + 'certs' + sep, settings.get_cert_path())
158157

159-
def testGetExtLibPath(self):
158+
settings.set_cert_path('/tmp')
159+
self.assertEqual('/tmp', settings.get_cert_path())
160+
161+
def testGetLibPath(self):
160162
"""
161-
Tests getExtLibPath method of the OneLogin_Saml2_Settings
163+
Tests getLibPath method of the OneLogin_Saml2_Settings
162164
"""
165+
settingsInfo = self.loadSettingsJSON()
166+
settings = OneLogin_Saml2_Settings(settingsInfo)
167+
path = settings.get_base_path()
168+
self.assertEqual(settings.get_lib_path(), join(dirname(dirname(dirname(dirname(dirname(__file__))))), 'src/onelogin/saml2/'))
169+
self.assertEqual(path, join(dirname(dirname(dirname(dirname(dirname(__file__))))), 'src/onelogin/saml2/../../../tests/data/customPath/'))
170+
171+
del settingsInfo['custom_base_path']
172+
settings = OneLogin_Saml2_Settings(settingsInfo)
173+
path = settings.get_base_path()
174+
self.assertEqual(settings.get_lib_path(), join(dirname(dirname(dirname(dirname(dirname(__file__))))), 'src/onelogin/saml2/'))
175+
self.assertEqual(path, join(dirname(dirname(dirname(dirname(dirname(__file__))))), 'src/'))
176+
163177
settings = OneLogin_Saml2_Settings(custom_base_path=self.settings_path)
164-
base = settings.get_base_path()
165-
self.assertEqual(join(base, 'extlib') + sep, settings.get_ext_lib_path())
178+
path = settings.get_base_path()
179+
self.assertEqual(settings.get_lib_path(), join(dirname(dirname(dirname(dirname(dirname(__file__))))), 'src/onelogin/saml2/'))
180+
self.assertEqual(path, join(dirname(dirname(dirname(dirname(__file__)))), 'settings/'))
166181

167182
def testGetSchemasPath(self):
168183
"""
169184
Tests getSchemasPath method of the OneLogin_Saml2_Settings
170185
"""
186+
settingsInfo = self.loadSettingsJSON()
187+
settings = OneLogin_Saml2_Settings(settingsInfo)
188+
path = settings.get_base_path()
189+
self.assertEqual(settings.get_schemas_path(), join(dirname(dirname(dirname(dirname(dirname(__file__))))), 'src/onelogin/saml2/schemas/'))
190+
self.assertEqual(path, join(dirname(dirname(dirname(dirname(dirname(__file__))))), 'src/onelogin/saml2/../../../tests/data/customPath/'))
191+
192+
del settingsInfo['custom_base_path']
193+
settings = OneLogin_Saml2_Settings(settingsInfo)
194+
path = settings.get_base_path()
195+
self.assertEqual(settings.get_schemas_path(), join(dirname(dirname(dirname(dirname(dirname(__file__))))), 'src/onelogin/saml2/schemas/'))
196+
self.assertEqual(path, join(dirname(dirname(dirname(dirname(dirname(__file__))))), 'src/'))
197+
171198
settings = OneLogin_Saml2_Settings(custom_base_path=self.settings_path)
172-
base = settings.get_base_path()
173-
self.assertEqual(join(base, 'lib', 'schemas') + sep, settings.get_schemas_path())
199+
path = settings.get_base_path()
200+
self.assertEqual(settings.get_schemas_path(), join(dirname(dirname(dirname(dirname(dirname(__file__))))), 'src/onelogin/saml2/schemas/'))
201+
self.assertEqual(path, join(dirname(dirname(dirname(dirname(__file__)))), 'settings/'))
174202

175203
def testGetIdPSSOurl(self):
176204
"""

0 commit comments

Comments
 (0)