From b86049a3fc25a46bddcfdb2f05964380adbd15d3 Mon Sep 17 00:00:00 2001 From: demonduck Date: Wed, 13 Sep 2017 11:58:55 -0400 Subject: [PATCH 1/2] bug fixes --- docs/conf.py | 3 +-- server/first_core/auth.py | 13 +++++++------ server/first_core/dbs/builtin_db.py | 6 ++---- server/www/views.py | 2 +- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 05ddb4f..20738bf 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -42,8 +42,7 @@ # Autodoc settings autoclass_content = 'class' autodoc_mock_imports = ['httplib2', 'oauth2client', 'apiclient', 'mongoengine', - 'django', 'bson', 'distorm3', 'mongoengine.queryset', - 'bson.objectid'] + 'django', 'capstone', 'mongoengine.queryset'] class _MyMockModule(sphinx.ext.autodoc._MockModule): '''Class created to get around autodoc issues with server's dependencies.''' diff --git a/server/first_core/auth.py b/server/first_core/auth.py index 9cd474d..cc4b775 100644 --- a/server/first_core/auth.py +++ b/server/first_core/auth.py @@ -32,12 +32,14 @@ from functools import wraps # Django Modules +from django.core.exceptions import ObjectDoesNotExist from django.http import HttpResponse, HttpRequest from django.shortcuts import render, redirect from django.urls import reverse # FIRST Modules # TODO: Use DBManager to get user objects and do User operations +from first.settings import CONFIG from first_core.models import User from first_core.error import FIRSTError @@ -45,7 +47,6 @@ import httplib2 from oauth2client import client from apiclient import discovery -from mongoengine.queryset import DoesNotExist @@ -118,7 +119,7 @@ class Authentication(): def __init__(self, request): self.request = request redirect_uri = request.build_absolute_uri(reverse('www:oauth', kwargs={'service' : 'google'})) - secret = os.environ.get('GOOGLE_SECRET', '/usr/local/etc/google_secret.json') + secret = CONFIG.get('oauth_path', '/usr/local/etc/google_secret.json') try: self.flow = {'google' : client.flow_from_clientsecrets(secret, scope=['https://www.googleapis.com/auth/userinfo.profile', @@ -200,7 +201,7 @@ def login_step_2(self, auth_code, url, login=True): return redirect(url) - except DoesNotExist: + except ObjectDoesNotExist: self.request.session.flush() raise FIRSTAuthError('User is not registered.') @@ -236,7 +237,7 @@ def register_user(self): user = None continue - except DoesNotExist: + except ObjectDoesNotExist: pass # Create random 4 digit value for the handle @@ -248,7 +249,7 @@ def register_user(self): user = User.objects.get(handle=handle, number=num) user = None - except DoesNotExist: + except ObjectDoesNotExist: user = User(name=name, email=email, api_key=api_key, @@ -269,5 +270,5 @@ def get_user_data(email): user = User.objects.get(email=email) return user - except DoesNotExist: + except ObjectDoesNotExist: return None diff --git a/server/first_core/dbs/builtin_db.py b/server/first_core/dbs/builtin_db.py index 4bfd76a..e140b9d 100644 --- a/server/first_core/dbs/builtin_db.py +++ b/server/first_core/dbs/builtin_db.py @@ -32,8 +32,6 @@ from hashlib import md5 # Third Party Modules -import bson - from django.utils import timezone from django.core.paginator import Paginator from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned @@ -161,14 +159,14 @@ def get_function(self, opcodes, architecture, apis, create=False, **kwargs): try: function = Function.objects.get(sha256=sha256_hash, - opcodes=bson.Binary(opcodes), + opcodes=opcodes, architecture=architecture) #, #apis__api=apis) except ObjectDoesNotExist: if create: # Create function and add it to sample function = Function.objects.create( sha256=sha256_hash, - opcodes=bson.Binary(opcodes), + opcodes=opcodes, architecture=architecture) apis_ = [FunctionApis.objects.get_or_create(x)[0] for x in apis] diff --git a/server/www/views.py b/server/www/views.py index 6fb7458..089658d 100644 --- a/server/www/views.py +++ b/server/www/views.py @@ -38,7 +38,7 @@ def profile(request): if not user: return redirect(reverse('www:index')) - count = Function.objects(metadata__user=user).count() + count = Function.objects.filter(metadata__user=user).count() data = {'title' : 'Profile', 'user' : user.dump(True), 'metadata_count' : count} From ac5bd964a40022bf9bd68677937ee9cd25a52850 Mon Sep 17 00:00:00 2001 From: demonduck Date: Wed, 13 Sep 2017 12:22:47 -0400 Subject: [PATCH 2/2] removing auto imports no longer used --- docs/conf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 20738bf..ce9f27d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -41,8 +41,8 @@ # Autodoc settings autoclass_content = 'class' -autodoc_mock_imports = ['httplib2', 'oauth2client', 'apiclient', 'mongoengine', - 'django', 'capstone', 'mongoengine.queryset'] +autodoc_mock_imports = ['httplib2', 'oauth2client', 'apiclient', + 'django', 'capstone'] class _MyMockModule(sphinx.ext.autodoc._MockModule): '''Class created to get around autodoc issues with server's dependencies.'''