Example #1
0
    def post(self):
        username = self.get_argument("username")
        password = self.get_argument("password")
        user_type = self.get_argument("type")
        public_key = self.get_argument("public_key")

        current_username = self.get_secure_cookie("username")
        query_data = UserMeta.query.filter_by(username=current_username).first()
        if query_data.user_type != 1:
            raise HTTPError(403)

        public_key_path = new_user_public_key(public_key)
        user = UserMeta(username=username, user_type=int(user_type),
                        password=password, public_key=public_key_path)
        session.add(user)
        session.commit()
        session.close()

        self.write({"msg": "success"})
Example #2
0
    def test_new_user_public_key(self, _uuid, _os, _open):
        _os.path.expanduser.return_value = "/home/user"
        _os.path.join.return_value = "/home/user/.ssh/public_key_filname.pub"
        _uuid.uuid1 = mock.Mock()
        _uuid.uuid1.return_value = "sampleuuid"
        _public_key_file = mock.MagicMock(spec=file)
        _open.return_value = _public_key_file

        result = new_user_public_key(ssh_public_key="sample_public_key")

        self.assertEqual(result, "/home/user/.ssh/public_key_filname.pub")
        _os.path.expanduser.assert_called_once_with("~")
        _uuid.uuid1.assert_called_once_with()
        _os.path.join.assert_called_once_with(
            "/home/user", ".ssh", "sampleuuid.pub"
        )
        _public_key_file.__enter__.return_value.write.assert_called_once_with(
            "sample_public_key\r\n"
        )