def test_location_ok(self): auth = GarageAuth(self._config) self.assertEqual(6, int(auth.location( (0,0.1) ))) self._config.reload.assert_called_with()
def test_token_response_2(self): urlopenmock = MagicMock(return_value='{ "audience": "12345", "email": "personb" } ') auth = GarageAuth(self._config, urlopen=urlopenmock) self.assertEqual("personb", auth.token("mytoken")) self._config.reload.assert_called_with()
def test_location_too_far(self): auth = GarageAuth(self._config) with self.assertRaises(AuthError): auth.location( (0,0.2) )
def test_token_invalid_audience(self): urlopenmock = MagicMock(return_value='{ "audience": "54321", "email": "persona" } ') auth = GarageAuth(self._config, urlopen=urlopenmock) with self.assertRaises(AuthError): auth.token("mytoken")
def test_token_email_not_exist(self): urlopenmock = MagicMock(return_value='{ "audience": "12345", "emails": "persona" } ') auth = GarageAuth(self._config, urlopen=urlopenmock) with self.assertRaises(AuthError): auth.token("mytoken")
def test_token_error_with_response(self): urlopenmock = MagicMock(return_value="<html><body>rubbish</body></html> ") auth = GarageAuth(self._config, urlopen=urlopenmock) with self.assertRaises(AuthError): auth.token("mytoken")
def test_token_error(self): urlopenmock = MagicMock(return_value='{ "error": "some error"} ') auth = GarageAuth(self._config, urlopen=urlopenmock) with self.assertRaises(AuthError): auth.token("mytoken")
def test_forwarded_user_persona(self): auth = GarageAuth(self._config) self.assertEqual("personb",auth.user("personb"))
def test_forwarded_user_none(self): auth = GarageAuth(self._config) with self.assertRaises(AuthError): auth.user(None)
from bottle import install, route, post, static_file, run, redirect, get, request from garage import Garage from time import sleep from garage_notify import GarageNotify import pifacedigitalio from threading import Lock, Thread from garage_auth import GarageAuth, AuthError import logging, logging.handlers from garage_dao import GarageDao from garage_config import GarageConfig from os.path import dirname, join from garage_state_mon import LastStateTransitionMonitor config = GarageConfig() auth = GarageAuth(config) dao = GarageDao() logger = logging.getLogger("garage_service") door_switch_lock = Lock() sensor_callback_lock = Lock() _AUTH_ERROR = {'auth': "Authorisation Error"} _AUTH_OK = {'auth': 'OK'} _WEB_ROOT = '/gc' def auth_ok(response): response.update(_AUTH_OK) return response