Esempio n. 1
0
    def test_checkTimeCookie(self):
        logging.info("Test checkTimeCookie")
        sanitizer = s.Sanitizer(loadconfig.load_json_file()["server"])

        # must be on the form "%Y-%m-%d %H:%M:%S" --> example "2019-01-01 00:00:00"
        # based on sanitize.__TIME_BETWEEN_POSTS = 10 (seconds)

        # Check now
        now = datetime.datetime.now()
        cookieTime = now.strftime("%Y-%m-%d %H:%M:%S")
        self.assertFalse(sanitizer.checkTimeCookie(cookieTime))

        # Check tomorrow
        now = datetime.datetime.now() + datetime.timedelta(days=1)
        cookieTime = now.strftime("%Y-%m-%d %H:%M:%S")
        self.assertFalse(sanitizer.checkTimeCookie(cookieTime))

        # Check now minus 9 seconds
        now = datetime.datetime.now() - datetime.timedelta(seconds=9)
        cookieTime = now.strftime("%Y-%m-%d %H:%M:%S")
        self.assertFalse(sanitizer.checkTimeCookie(cookieTime))

        # Check now minus 10 seconds
        now = datetime.datetime.now() - datetime.timedelta(seconds=10)
        cookieTime = now.strftime("%Y-%m-%d %H:%M:%S")
        self.assertTrue(sanitizer.checkTimeCookie(cookieTime))

        # Check some day in the past
        cookieTime = "2019-01-01 00:00:00"
        self.assertTrue(sanitizer.checkTimeCookie(cookieTime))
Esempio n. 2
0
    def test_checkHashCookie(self):
        logging.info("Test checkHashCookie")
        sanitizer = s.Sanitizer(loadconfig.load_json_file()["server"])

        cookieHash1 = sanitizer.getHashCookie().decode('utf-8')
        self.assertTrue(sanitizer.checkHashCookie(cookieHash1))

        # hash generated by sanitizer with some characters changed, should be unvalid
        cookieHash2 = "$2b$12$swUd.H2yI1GFO05h/946o.v8qJS4eQE8y0fMxt5u2Nr433wAGWQDW"
        self.assertFalse(sanitizer.checkHashCookie(cookieHash2))
def run():
    """Runs the script and it's functions
    """
    try:
        opts, args = getopt.getopt(sys.argv[1:], "", ["logLevel=", "logFile="])
        logging.basicConfig(format="%(levelname)s: %(message)s",
                            level=logging.INFO)

        #Parse command line arguments
        for opt, arg in opts:
            if opt == "--logLevel":
                logger = logging.getLogger()
                if arg == "CRITICAL":
                    logging.info("Setting log level to critical")
                    logger.setLevel(level=logging.CRITICAL)
                elif arg == "ERROR":
                    logging.info("Setting log level to error")
                    logger.setLevel(level=logging.ERROR)
                elif arg == "WARNING":
                    logging.info("Setting log level to warning")
                    logger.setLevel(level=logging.WARNING)
                elif arg == "INFO":
                    logging.info("Setting log level to info")
                    logger.setLevel(level=logging.INFO)
                elif arg == "DEBUG":
                    logging.info("Setting log level to debug")
                    logger.setLevel(level=logging.DEBUG)
                elif arg == "NONE":
                    logging.info("Disabling logging")
                    logging.disable(logging.CRITICAL)
                else:
                    raise ValueError("Invalid logLevel argument " + arg)
            elif opt == "--logFile":
                flog_handler = logging.FileHandler(arg)
                flog_handler.setLevel(logging.INFO)
                flog_format = logging.Formatter(
                    "%(asctime)s %(filename)s %(lineno)s %(funcName)s, %(levelname)s: %(message)s"
                )
                flog_handler.setFormatter(flog_format)
                logging.getLogger().addHandler(flog_handler)

        filedata = loadconfig.load_json_file()
        filedata = filedata["database"]
        __run_setup_files(filedata)
    except getopt.GetoptError:
        print("Usage:", os.path.basename(__file__),
              "--logLevel <logLevel> --logFile <logFile>")
    except OSError:
        logging.exception("OSError")
    except ValueError as e:
        logging.error("ValueError: %s", e)
    except:
        logging.exception("Unknown exception")
Esempio n. 4
0
    def test_getHashCookie(self):
        logging.info("Test getHashCookie")
        sanitizer = s.Sanitizer(loadconfig.load_json_file()["server"])

        # Should generate and print 3 different cookies
        cookie = sanitizer.getHashCookie()
        print("cookie 1", cookie)

        cookie = sanitizer.getHashCookie()
        print("cookie 2", cookie)

        cookie = sanitizer.getHashCookie()
        print("cookie 3", cookie)

        self.assertNotIn(sanitizer.getHashCookie(), sanitizer.getHashCookie())
Esempio n. 5
0
from flask import Flask, render_template, request, jsonify, make_response
from flask_googlemaps import GoogleMaps
from flask_googlemaps import Map
import os, sys, sanitize, datetime, controller

dir_loadconfig = os.path.dirname(os.path.dirname(__file__))
sys.path.insert(0, dir_loadconfig)
import loadconfig

app = Flask(__name__, template_folder=".")
#path from where this file is executed.
path = os.path.dirname(os.path.realpath(__file__))

config = loadconfig.load_json_file()

#sanitizer
sanitizer = sanitize.Sanitizer(config["server"])  # Verkar inte användas

#controller
Controller = controller.Controller(config)

config = None
del config

#What icon to show on map (flagged location & current location of user).
flaggedLocationsIcon = "http://maps.google.com/mapfiles/ms/icons/green-dot.png"  #http://maps.google.com/mapfiles/ms/icons/blue-dot.png
currentLocationIcon = "http://maps.google.com/mapfiles/dir_0.png"

#marks which combine the icon and flaggedLocations.
marks = []