Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PWL-751: require country field for institution PYTHON-V3 #62

Open
wants to merge 19 commits into
base: release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
19bca06
PWL-773: Add unit test for API end points in operation.
ChenXingguo Aug 14, 2019
daad678
PWL-742: Code change in accordance with Python upgrade 2.7 -> 3.6, Dj…
ChenXingguo Sep 11, 2019
93505f3
PWL-742: Fix check model has attribute bug.
ChenXingguo Nov 11, 2019
ca093f0
PWL-742: Fix bug introduced by last commit.
ChenXingguo Jan 9, 2020
1e9691d
Add docker files to containerize the application.
ChenXingguo Jul 2, 2022
d887370
Update Dockerfile.
ChenXingguo Jul 13, 2022
e14309c
Reformatted python code to remove trailing spaces.
ChenXingguo Jul 13, 2022
2399ce1
PWL-764 validation error handling
MichaelXiaoKun Jul 27, 2022
c509376
PWL-770: Add logging for activation code purchase email.
ChenXingguo Jul 29, 2022
73c5281
PWL-477: Updated put method in ConsortiumCRUD and InstitutionCRUD
MichaelXiaoKun Aug 2, 2022
3e96f43
Add test runner to skip error logging for exception assertion in the …
ChenXingguo Aug 4, 2022
cb42764
Handle validation failure for generic put request.
ChenXingguo Aug 4, 2022
28770c9
And method to compare request data with database result.
ChenXingguo Aug 5, 2022
f828edc
PWL-477: Added test cases for institution PUT request in party
MichaelXiaoKun Aug 18, 2022
0637a58
Fix Python 3 dependencies error.
ChenXingguo Aug 11, 2022
1865fde
PWL-477: add test cases for update consortium profile
MichaelXiaoKun Aug 19, 2022
95772b0
Remove host configuration as host is not used for the Django Test Cli…
ChenXingguo Oct 17, 2022
a5b286e
Add generic test sample template to make the test class inheritance m…
ChenXingguo Oct 20, 2022
e8fe66d
PWL-751: require country field for institution PYTHON-V3
kartikphoenix Nov 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Dockerfile*
docker-compose*
.dockerignore
.git
.gitignore
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM amazonlinux:2017.09.0.20170930

RUN yum -y install vim httpd python36 python36-devel python36-pip wget gcc gcc-c++ subversion make uuid libuuid-devel httpd-devel mysql-devel
# set python 3.6 as default version
RUN alternatives --install /usr/bin/python python /usr/bin/python2.7 1 && alternatives --install /usr/bin/python python /usr/bin/python3.6 2 && alternatives --set python /usr/bin/python3.6
RUN wget https://github.com/GrahamDumpleton/mod_wsgi/archive/4.5.15.tar.gz && tar -xvf 4.5.15.tar.gz && cd mod_wsgi-4.5.15 && ./configure --with-python=/usr/bin/python36 && make; make install && cd .. && rm -r mod_wsgi-4.5.15 4.5.15.tar.gz
# configure settings.py as part of build process
COPY docker_config/vhosts.conf /etc/httpd/conf.d/
COPY docker_config/wsgi.conf /etc/httpd/conf.d/
COPY dependencies.list /etc/
RUN easy_install-3.6 pip && pip3 install --upgrade pip
RUN pip3 install -r /etc/dependencies.list && rm /etc/dependencies.list
# update this to pipe to AWS log later
RUN mkdir /var/log/api && chown -R apache:apache /var/log/api
RUN echo "ServerName 172.*" >> /etc/httpd/conf/httpd.conf
EXPOSE 80
CMD ["/usr/sbin/httpd","-D","FOREGROUND"]
2 changes: 1 addition & 1 deletion apikey/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals


from django.db import models, migrations

Expand Down
39 changes: 0 additions & 39 deletions apikey/pyTests.py

This file was deleted.

2 changes: 1 addition & 1 deletion apikey/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Copyright 2015 Phoenix Bioinformatics Corporation. All rights reserved.

from models import ApiKey
from .models import ApiKey
from rest_framework import serializers

class ApiKeySerializer(serializers.ModelSerializer):
Expand Down
18 changes: 8 additions & 10 deletions apikey/testSamples.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import django
import unittest
import sys, getopt
from unittest import TestCase
from models import ApiKey
import sys
from django.test import TestCase
from .models import ApiKey
from common.tests import TestGenericInterfaces

from common.pyTests import PyTestGenerics

genericForcePost = PyTestGenerics.forcePost
genericForcePost = TestGenericInterfaces.forcePost

class ApiKeySample():
path = 'apikeys/'
Expand All @@ -15,13 +13,13 @@ class ApiKeySample():
'apiKey':'proxyKey',
}
updateData = {
'apiKey':'proxy2Key',
'apiKey':'proxyKey2',
}
pkName = 'apiKeyId'
model = ApiKey

def __init__(self, serverUrl):
self.url = serverUrl+self.path
self.url = serverUrl + self.path

def forcePost(self,data):
def forcePost(self, data):
return genericForcePost(self.model, self.pkName, data)
34 changes: 33 additions & 1 deletion apikey/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
#Copyright 2015 Phoenix Bioinformatics Corporation. All rights reserved.

import django
import unittest
import sys
import requests
import json
from django.test import TestCase
from .models import ApiKey
from .testSamples import ApiKeySample
from common.tests import TestGenericInterfaces, GenericCRUDTest
from http.cookies import SimpleCookie

# Create your tests here.
django.setup()
serverUrl = TestGenericInterfaces.getHost()

# ---------------------- UNIT TEST FOR BASIC CRUD OPERATIONS -------------

class ApiKeyCRUD(GenericCRUDTest, TestCase):
sample = ApiKeySample(serverUrl)

def test_for_get_all(self):
url = self.getUrl(self.sample.url)
self.getAllHelper(url, 'apiKey', self.apiKey)

# ----------------- END OF BASIC CRUD OPERATIONS ----------------------

print("Running unit tests on API key web services API.........")

# Create your tests here.
if __name__ == '__main__':
sys.argv[1:] = []
unittest.main()
ret = not runner.run(suite).wasSuccessful()
sys.exit(ret)
4 changes: 2 additions & 2 deletions apikey/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from django.http import HttpResponse
from rest_framework import generics

from models import ApiKey
from serializers import ApiKeySerializer
from .models import ApiKey
from .serializers import ApiKeySerializer

import json

Expand Down
38 changes: 38 additions & 0 deletions authentication/manualTests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#Copyright 2015 Phoenix Bioinformatics Corporation. All rights reserved.

import django
import unittest
import sys
import json
from django.test import TestCase, Client
from partner.testSamples import PartnerSample
from party.testSamples import UserPartySample
from common.tests import TestGenericInterfaces, GenericTest
from .testSamples import CredentialSample
from .tests import CredentialGenericTest
from http.cookies import SimpleCookie
from django.test.utils import override_settings

# Create your tests here.
django.setup()
serverUrl = TestGenericInterfaces.getHost()

# test for API endpoint /credentials/resetPwd/
@override_settings(EMAIL_BACKEND='django.core.mail.backends.smtp.EmailBackend')
class ResetPasswordTest(CredentialGenericTest):

def test_for_reset_password(self):
url = '%scredentials/resetPwd/?user=%s&partnerId=%s' % (serverUrl, self.sample.getUsername(), self.partnerId)

# the default content type for put is 'application/octet-stream'
# does not test for partyId update
res = self.client.put(url, None, content_type='application/json')
self.assertEqual(res.status_code, 200)

print("Running unit tests on authentication/credential reset password web services API.........")

if __name__ == '__main__':
sys.argv[1:] = []
unittest.main()
ret = not runner.run(suite).wasSuccessful()
sys.exit(ret)
6 changes: 3 additions & 3 deletions authentication/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals


from django.db import models, migrations

Expand All @@ -16,7 +16,7 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('gmail', models.CharField(max_length=128, db_index=True)),
('partyId', models.ForeignKey(to='party.Party')),
('partyId', models.ForeignKey(to='party.Party', on_delete=models.PROTECT)),
],
options={
'db_table': 'GoogleEmail',
Expand All @@ -30,7 +30,7 @@ class Migration(migrations.Migration):
('password', models.CharField(max_length=32)),
('email', models.CharField(max_length=128, null=True)),
('institution', models.CharField(max_length=64, null=True)),
('partyId', models.ForeignKey(to='party.Party', db_column=b'partyId')),
('partyId', models.ForeignKey(to='party.Party', db_column='partyId', on_delete=models.PROTECT)),
],
options={
'db_table': 'User',
Expand Down
4 changes: 2 additions & 2 deletions authentication/migrations/0002_auto_20150806_1926.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals


from django.db import models, migrations

Expand All @@ -15,7 +15,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='user',
name='partnerId',
field=models.ForeignKey(db_column=b'partnerId', default='test', to='partner.Partner'),
field=models.ForeignKey(db_column='partnerId', default='test', to='partner.Partner', on_delete=models.PROTECT),
preserve_default=False,
),
migrations.AddField(
Expand Down
2 changes: 1 addition & 1 deletion authentication/migrations/0003_auto_20150821_2103.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals


from django.db import models, migrations

Expand Down
2 changes: 1 addition & 1 deletion authentication/migrations/0004_credential_name.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals


from django.db import models, migrations

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals


from django.db import migrations, models

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals


from django.db import migrations, models

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals


from django.db import models, migrations

Expand Down
2 changes: 1 addition & 1 deletion authentication/migrations/0008_auto_20160820_1956.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals


from django.db import models, migrations

Expand Down
21 changes: 15 additions & 6 deletions authentication/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,44 @@ class Credential(models.Model):
password = models.CharField(max_length=64)
email = models.CharField(max_length=254, null=True)
institution = models.CharField(max_length=200, null=True)#PW-254
partyId = models.ForeignKey(Party, db_column='partyId')
partnerId = models.ForeignKey(Partner, db_column='partnerId')
partyId = models.ForeignKey(Party, db_column='partyId', on_delete=models.PROTECT)
partnerId = models.ForeignKey(Partner, db_column='partnerId', on_delete=models.PROTECT)
userIdentifier = models.CharField(max_length=32, null=True)
#name = models.CharField(max_length=64, null=True) vet PW-161

@staticmethod
def validate(partyId, secretKey):
if partyId and secretKey and partyId.isdigit() and Party.objects.filter(partyId=partyId).exists():
pu = Party.objects.filter(partyId=partyId)
if Credential.objects.filter(partyId_id__in=pu.values('partyId')).exists():
usu = Credential.objects.filter(partyId_id__in=pu.values('partyId')).first()
digested = base64.b64encode(hmac.new(str(partyId).encode('ascii'), usu.password.encode('ascii'), hashlib.sha1).digest())
digested = Credential.generateSecretKey(partyId, usu.password)
if digested == secretKey:
return True
#TODO: validation still fail
pu = pu.first().consortiums.all()
if Credential.objects.filter(partyId_id__in=pu.values('partyId')).exists():
for usu in Credential.objects.filter(partyId_id__in=pu.values('partyId')):
digested = base64.b64encode(hmac.new(str(usu.partyId).encode('ascii'), usu.password.encode('ascii'), hashlib.sha1).digest())
digested = Credential.generateSecretKey(usu.partyId, usu.password)
if digested == secretKey:
return True
return False

@staticmethod
def generatePasswordHash(password):
return hashlib.sha1(password.encode()).hexdigest()

@staticmethod
def generateSecretKey(partyId, password):
encoded = base64.b64encode(hmac.new(str(partyId).encode('ascii'), password.encode('ascii'), hashlib.sha1).digest())
return encoded.decode()

class Meta:
db_table = "Credential"
unique_together = ("username","partnerId")

class GooglePartyAffiliation(models.Model):
gmail = models.CharField(max_length=128, db_index=True)
partyId = models.ForeignKey(Party)
partyId = models.ForeignKey(Party, on_delete=models.PROTECT)
class Meta:
db_table = "GoogleEmail"
Loading