Commit 1e856012 authored by Nicolas Wavrant's avatar Nicolas Wavrant Committed by Cédric Le Ninivin

runner: reads recovery code from knowledge0 file

runner: tests do not use .rcode file anymore

runner: rcode is now in public section

runner: running tests do not change rcode
parent d8e79b2b
...@@ -20,7 +20,8 @@ import shutil ...@@ -20,7 +20,8 @@ import shutil
import time import time
import unittest import unittest
from slapos.runner.utils import (getProfilePath, getSession, isInstanceRunning, from slapos.runner.utils import (getProfilePath, getRcode,
getSession, isInstanceRunning,
isSoftwareRunning, startProxy, isSoftwareRunning, startProxy,
isSoftwareReleaseReady, isSoftwareReleaseReady,
runSlapgridUntilSuccess, runSlapgridUntilSuccess,
...@@ -69,7 +70,6 @@ class SlaprunnerTestCase(unittest.TestCase): ...@@ -69,7 +70,6 @@ class SlaprunnerTestCase(unittest.TestCase):
views.app.config['TESTING'] = True views.app.config['TESTING'] = True
self.users = ["slapuser", "slappwd", "slaprunner@nexedi.com", "SlapOS web runner"] self.users = ["slapuser", "slappwd", "slaprunner@nexedi.com", "SlapOS web runner"]
self.updateUser = ["newslapuser", "newslappwd", "slaprunner@nexedi.com", "SlapOS web runner"] self.updateUser = ["newslapuser", "newslappwd", "slaprunner@nexedi.com", "SlapOS web runner"]
self.rcode = "41bf2657"
self.repo = 'http://git.erp5.org/repos/slapos.git' self.repo = 'http://git.erp5.org/repos/slapos.git'
self.software = "workspace/slapos/software/" # relative directory fo SR self.software = "workspace/slapos/software/" # relative directory fo SR
self.project = 'slapos' # Default project name self.project = 'slapos' # Default project name
...@@ -103,8 +103,9 @@ class SlaprunnerTestCase(unittest.TestCase): ...@@ -103,8 +103,9 @@ class SlaprunnerTestCase(unittest.TestCase):
self.app = views.app.test_client() self.app = views.app.test_client()
self.app.config = views.app.config self.app.config = views.app.config
#Create password recover code #Create password recover code
with open(os.path.join(views.app.config['etc_dir'], '.rcode'), 'w') as rpwd: parser = ConfigParser.ConfigParser()
rpwd.write(self.rcode) parser.read(self.app.config['knowledge0_cfg'])
self.rcode = parser.get('public', 'recovery-code')
#Create config.json #Create config.json
json_file = os.path.join(views.app.config['etc_dir'], 'config.json') json_file = os.path.join(views.app.config['etc_dir'], 'config.json')
if not os.path.exists(json_file): if not os.path.exists(json_file):
...@@ -118,7 +119,6 @@ class SlaprunnerTestCase(unittest.TestCase): ...@@ -118,7 +119,6 @@ class SlaprunnerTestCase(unittest.TestCase):
def tearDown(self): def tearDown(self):
"""Remove all test data""" """Remove all test data"""
os.unlink(os.path.join(self.app.config['etc_dir'], '.rcode'))
project = os.path.join(self.app.config['etc_dir'], '.project') project = os.path.join(self.app.config['etc_dir'], '.project')
users = os.path.join(self.app.config['etc_dir'], '.users') users = os.path.join(self.app.config['etc_dir'], '.users')
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# vim: set et sts=2: # vim: set et sts=2:
# pylint: disable-msg=W0311,C0301,C0103,C0111,W0141,W0142 # pylint: disable-msg=W0311,C0301,C0103,C0111,W0141,W0142
import ConfigParser
import json import json
import logging import logging
import md5 import md5
...@@ -112,6 +113,15 @@ def saveSession(config, account): ...@@ -112,6 +113,15 @@ def saveSession(config, account):
return str(e) return str(e)
def getRcode(config):
parser = ConfigParser.ConfigParser()
try:
parser.read(config['knowledge0_cfg'])
return parser.get('public', 'recovery-code')
except (ConfigParser.NoSectionError, IOError) as e:
return None
def createNewUser(config, name, passwd): def createNewUser(config, name, passwd):
htpasswdfile = os.path.join(config['etc_dir'], '.htpasswd') htpasswdfile = os.path.join(config['etc_dir'], '.htpasswd')
if os.path.exists(htpasswdfile): if os.path.exists(htpasswdfile):
......
...@@ -16,7 +16,7 @@ from slapos.runner.process import killRunningProcess ...@@ -16,7 +16,7 @@ from slapos.runner.process import killRunningProcess
from slapos.runner.utils import (checkSoftwareFolder, configNewSR, from slapos.runner.utils import (checkSoftwareFolder, configNewSR,
createNewUser, getProfilePath, createNewUser, getProfilePath,
listFolder, getBuildAndRunParams, listFolder, getBuildAndRunParams,
getProjectTitle, getSession, getProjectTitle, getRcode, getSession,
getSlapStatus, getSvcStatus, getSlapStatus, getSvcStatus,
getSvcTailProcess, isInstanceRunning, getSvcTailProcess, isInstanceRunning,
isSoftwareRunning, isSoftwareReleaseReady, isText, isSoftwareRunning, isSoftwareReleaseReady, isText,
...@@ -552,7 +552,7 @@ def updateBuildAndRunConfig(): ...@@ -552,7 +552,7 @@ def updateBuildAndRunConfig():
#update user account data #update user account data
def updateAccount(): def updateAccount():
code = request.form['rcode'].strip() code = request.form['rcode'].strip()
recovery_code = open(os.path.join(app.config['etc_dir'], ".rcode"), "r").read() recovery_code = getRcode(app.config)
if code != recovery_code: if code != recovery_code:
return jsonify(code=0, result="Your password recovery code is not valid!") return jsonify(code=0, result="Your password recovery code is not valid!")
...@@ -583,8 +583,7 @@ def configAccount(): ...@@ -583,8 +583,7 @@ def configAccount():
account.append(request.form['email'].strip()) account.append(request.form['email'].strip())
account.append(request.form['name'].strip()) account.append(request.form['name'].strip())
code = request.form['rcode'].strip() code = request.form['rcode'].strip()
recovery_code = open(os.path.join(app.config['etc_dir'], ".rcode"), recovery_code = getRcode(app.config)
"r").read().strip()
if code != recovery_code: if code != recovery_code:
return jsonify(code=0, result="Your password recovery code is not valid!") return jsonify(code=0, result="Your password recovery code is not valid!")
result = saveSession(app.config, account) result = saveSession(app.config, account)
...@@ -595,8 +594,7 @@ def configAccount(): ...@@ -595,8 +594,7 @@ def configAccount():
def addUser(): def addUser():
code = request.form['rcode'].strip() code = request.form['rcode'].strip()
recovery_code = open(os.path.join(app.config['etc_dir'], ".rcode"), recovery_code = getRcode(app.config)
"r").read().strip()
if code != recovery_code: if code != recovery_code:
return jsonify(code=0, result="Your password recovery code is not valid!") return jsonify(code=0, result="Your password recovery code is not valid!")
if createNewUser(app.config, request.form['username'], if createNewUser(app.config, request.form['username'],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment