def test_01_save_resolver(self):
        # Save a resolver in the database

        # Try to create a resolver, which type does not exist:
        self.assertRaises(Exception, save_resolver, {"name": "testresolver", "type": "DNE", "filename": HOSTSFILE})

        # Try to create a resolver, with wrong name:
        self.assertRaises(Exception, save_resolver, {"name": "=====", "type": "hosts", "filename": HOSTSFILE})

        # Create a hosts resolver
        mr_obj = save_resolver(
            {"name": "testresolver", "type": "hosts", "filename": "somefile", "unknown_param": "xyz"}
        )
        self.assertTrue(mr_obj > 0)

        # update the resolver
        mr_obj = save_resolver(
            {
                "name": "testresolver",
                "type": "hosts",
                "filename": HOSTSFILE,
                "type.filename": "string",
                "desc.filename": "the filename with the " "hosts",
                "pw": "secret",
                "type.pw": "password",
            }
        )
        self.assertTrue(mr_obj > 0)

        # wrong machine resolver definitions
        # missing value with type
        self.assertRaises(Exception, save_resolver, {"name": "t2", "type": "hosts", "type.filename": "string"})

        # missing value with description
        self.assertRaises(Exception, save_resolver, {"name": "t2", "type": "hosts", "desc.filename": "s.t."})
Beispiel #2
0
    def test_01_save_resolver(self):
        # Save a resolver in the database

        # Try to create a resolver, which type does not exist:
        self.assertRaises(Exception, save_resolver, {
            "name": "testresolver",
            "type": "DNE",
            "filename": HOSTSFILE
        })

        # Try to create a resolver, with wrong name:
        self.assertRaises(Exception, save_resolver, {
            "name": "=====",
            "type": "hosts",
            "filename": HOSTSFILE
        })

        # Create a hosts resolver
        mr_obj = save_resolver({
            "name": "testresolver",
            "type": "hosts",
            "filename": "somefile",
            "unknown_param": "xyz"
        })
        self.assertTrue(mr_obj > 0)

        # update the resolver
        mr_obj = save_resolver({
            "name": "testresolver",
            "type": "hosts",
            "filename": HOSTSFILE,
            "type.filename": "string",
            "desc.filename": "the filename with the "
            "hosts",
            "pw": "secret",
            "type.pw": "password"
        })
        self.assertTrue(mr_obj > 0)

        # wrong machine resolver definitions
        # missing value with type
        self.assertRaises(Exception, save_resolver, {
            "name": "t2",
            "type": "hosts",
            "type.filename": "string"
        })

        # missing value with description
        self.assertRaises(Exception, save_resolver, {
            "name": "t2",
            "type": "hosts",
            "desc.filename": "s.t."
        })
Beispiel #3
0
 def test_00_setup(self):
     token1 = init_token({"type": "spass", "serial": self.serial})
     resolver1 = save_resolver({
         "name": self.resolvername,
         "type": "hosts",
         "filename": HOSTSFILE
     })
Beispiel #4
0
    def test_06_offline_auth(self):
        # Test that a machine definition will return offline hashes
        self.setUp_user_realms()
        serial = "offline01"
        tokenobject = init_token({
            "serial": serial,
            "type": "hotp",
            "otpkey": "3132333435363738393031"
            "323334353637383930",
            "pin": "offline",
            "user": "******"
        })

        # Set the Machine and MachineToken
        resolver1 = save_resolver({
            "name": "reso1",
            "type": "hosts",
            "filename": HOSTSFILE
        })

        mt = attach_token(serial, "offline", hostname="gandalf")
        self.assertEqual(mt.token.serial, serial)
        self.assertEqual(mt.token.machine_list[0].machine_id, "192.168.0.1")

        # The request with an OTP value and a PIN of a user, who has not
        # token assigned
        builder = EnvironBuilder(method='POST', data={}, headers={})
        env = builder.get_environ()
        env["REMOTE_ADDR"] = "192.168.0.1"
        req = Request(env)
        req.all_data = {"user": "******", "pass": "******"}

        res = {
            "jsonrpc": "2.0",
            "result": {
                "status": True,
                "value": True
            },
            "version": "privacyIDEA test",
            "detail": {
                "serial": serial
            },
            "id": 1
        }
        resp = Response(json.dumps(res))

        new_response = offline_info(req, resp)
        jresult = json.loads(new_response.data)
        self.assertTrue(jresult.get("result").get("value"), jresult)
        self.assertEqual(jresult.get("detail").get("serial"), serial)

        # Check the hashvalues in the offline tree
        auth_items = jresult.get("auth_items")
        self.assertEqual(len(auth_items), 1)
        response = auth_items.get("offline")[0].get("response")
        self.assertEqual(len(response), 100)
        # check if the counter of the token was increased to 100
        tokenobject = get_tokens(serial=serial)[0]
        self.assertEqual(tokenobject.token.count, 101)
        delete_policy("pol2")
    def test_08_get_webui_settings(self):
        # Test that a machine definition will return offline hashes
        self.setUp_user_realms()
        serial = "offline01"
        tokenobject = init_token({"serial": serial, "type": "hotp",
                                  "otpkey": "3132333435363738393031"
                                            "323334353637383930",
                                  "pin": "offline",
                                  "user": "******"})

        # Set the Machine and MachineToken
        resolver1 = save_resolver({"name": "reso1",
                                   "type": "hosts",
                                   "filename": HOSTSFILE})

        mt = attach_token(serial, "offline", hostname="gandalf")
        self.assertEqual(mt.token.serial, serial)
        self.assertEqual(mt.token.machine_list[0].machine_id, "192.168.0.1")

        # The request with an OTP value and a PIN of a user, who has not
        # token assigned
        builder = EnvironBuilder(method='POST',
                                 data={},
                                 headers={})
        env = builder.get_environ()
        env["REMOTE_ADDR"] = "192.168.0.1"
        g.client_ip = env["REMOTE_ADDR"]
        req = Request(env)
        req.all_data = {"user": "******",
                        "pass": "******"}

        res = {"jsonrpc": "2.0",
               "result": {"status": True,
                          "value": {"role": "user",
                                    "username": "******"}},
               "version": "privacyIDEA test",
               "detail": {"serial": serial},
               "id": 1}
        resp = Response(json.dumps(res))

        new_response = get_webui_settings(req, resp)
        jresult = json.loads(new_response.data)
        self.assertEqual(jresult.get("result").get("value").get(
            "token_wizard"), False)

        # Set a policy. User has not token, so "token_wizard" will be True
        set_policy(name="pol_wizard",
                   scope=SCOPE.WEBUI,
                   action=ACTION.TOKENWIZARD)
        g.policy_object = PolicyClass()
        new_response = get_webui_settings(req, resp)
        jresult = json.loads(new_response.data)
        self.assertEqual(jresult.get("result").get("value").get(
            "token_wizard"), True)

        delete_policy("pol_wizard")
    def test_06_offline_auth(self):
        # Test that a machine definition will return offline hashes
        self.setUp_user_realms()
        serial = "offline01"
        tokenobject = init_token({"serial": serial, "type": "hotp",
                                  "otpkey": "3132333435363738393031"
                                            "323334353637383930",
                                  "pin": "offline",
                                  "user": "******"})

        # Set the Machine and MachineToken
        resolver1 = save_resolver({"name": "reso1",
                                   "type": "hosts",
                                   "filename": HOSTSFILE})

        mt = attach_token(serial, "offline", hostname="gandalf")
        self.assertEqual(mt.token.serial, serial)
        self.assertEqual(mt.token.machine_list[0].machine_id, "192.168.0.1")

        # The request with an OTP value and a PIN of a user, who has not
        # token assigned
        builder = EnvironBuilder(method='POST',
                                 data={},
                                 headers={})
        env = builder.get_environ()
        env["REMOTE_ADDR"] = "192.168.0.1"
        g.client_ip = env["REMOTE_ADDR"]
        req = Request(env)
        req.all_data = {"user": "******",
                        "pass": "******"}

        res = {"jsonrpc": "2.0",
               "result": {"status": True,
                          "value": True},
               "version": "privacyIDEA test",
               "detail": {"serial": serial},
               "id": 1}
        resp = Response(json.dumps(res))

        new_response = offline_info(req, resp)
        jresult = json.loads(new_response.data)
        self.assertTrue(jresult.get("result").get("value"), jresult)
        self.assertEqual(jresult.get("detail").get("serial"), serial)

        # Check the hashvalues in the offline tree
        auth_items = jresult.get("auth_items")
        self.assertEqual(len(auth_items), 1)
        response = auth_items.get("offline")[0].get("response")
        self.assertEqual(len(response), 100)
        # check if the counter of the token was increased to 100
        tokenobject = get_tokens(serial=serial)[0]
        self.assertEqual(tokenobject.token.count, 101)
        delete_policy("pol2")
 def test_00_setup(self):
     token1 = init_token({"type": "spass", "serial": self.serial})
     resolver1 = save_resolver({"name": self.resolvername,
                                "type": "hosts",
                                "filename": HOSTSFILE})
    def test_08_get_webui_settings(self):
        # Test that a machine definition will return offline hashes
        self.setUp_user_realms()
        serial = "offline01"
        tokenobject = init_token({
            "serial": serial,
            "type": "hotp",
            "otpkey": "3132333435363738393031"
            "323334353637383930",
            "pin": "offline",
            "user": "******"
        })

        # Set the Machine and MachineToken
        resolver1 = save_resolver({
            "name": "reso1",
            "type": "hosts",
            "filename": HOSTSFILE
        })

        mt = attach_token(serial, "offline", hostname="gandalf")
        self.assertEqual(mt.token.serial, serial)
        self.assertEqual(mt.token.machine_list[0].machine_id, "192.168.0.1")

        # The request with an OTP value and a PIN of a user, who has not
        # token assigned
        builder = EnvironBuilder(method='POST', data={}, headers={})
        env = builder.get_environ()
        env["REMOTE_ADDR"] = "192.168.0.1"
        g.client_ip = env["REMOTE_ADDR"]
        req = Request(env)
        req.all_data = {"user": "******", "pass": "******"}

        res = {
            "jsonrpc": "2.0",
            "result": {
                "status": True,
                "value": {
                    "role": "user",
                    "username": "******"
                }
            },
            "version": "privacyIDEA test",
            "detail": {
                "serial": serial
            },
            "id": 1
        }
        resp = Response(json.dumps(res))

        new_response = get_webui_settings(req, resp)
        jresult = json.loads(new_response.data)
        self.assertEqual(
            jresult.get("result").get("value").get("token_wizard"), False)

        # Set a policy. User has not token, so "token_wizard" will be True
        set_policy(name="pol_wizard",
                   scope=SCOPE.WEBUI,
                   action=ACTION.TOKENWIZARD)
        g.policy_object = PolicyClass()
        new_response = get_webui_settings(req, resp)
        jresult = json.loads(new_response.data)
        self.assertEqual(
            jresult.get("result").get("value").get("token_wizard"), True)

        delete_policy("pol_wizard")