Skip to content

Commit

Permalink
Merge pull request #104 from Full-Tortuga/ci/final-integrations
Browse files Browse the repository at this point in the history
ci: final integrations
  • Loading branch information
JSnow11 authored Jan 10, 2022
2 parents 1be0c55 + 662ca6f commit 7083e6e
Show file tree
Hide file tree
Showing 77 changed files with 4,132 additions and 16,884 deletions.
10 changes: 6 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ wheels/
*.egg-info/
.installed.cfg
*.egg
migrations/

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down Expand Up @@ -60,8 +61,6 @@ coverage.xml
*.log
decide/local_settings.py

migrations/

# Flask stuff:
instance/
.webassets-cache
Expand Down Expand Up @@ -111,5 +110,8 @@ ENV/

.vagrant

# new db migrations
decide/*/migrations/0001_initial.py
#backups
decide/backups/backups/*

#migrations
decide/*/migrations
5 changes: 3 additions & 2 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% prepara el repositorio para su despliegue.
release: sh -c 'cd decide && python manage.py migrate'
% prepara el repositorio para su despliegue.
release: sh -c 'cd decide && python manage.py makemigrations && python manage.py migrate'

% especifica el comando para lanzar Decide
web: sh -c 'cd decide && gunicorn decide.wsgi --log-file -'
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Para configurar el proyecto, podremos crearnos un fichero local_settings.py basa
local_settings.example.py, donde podremos configurar la ruta de nuestras apps o escoger que módulos
ejecutar.

Se hará uso de la base de datos MongoDB, para el correcto funcionamiento de la aplicación será necesaria la instalación de dicha base de datos siguiendo las instrucciones de la documentación oficial según el SO que estemos utilizando:
Se hará uso de la base de datos MongoDB. Para el correcto funcionamiento de la aplicación será necesaria la instalación de dicha base de datos siguiendo las instrucciones de la documentación oficial según el SO que estemos utilizando:

Windows: - https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/

Expand All @@ -77,8 +77,6 @@ En caso de fallo al instalar las dependencias, es necesario instalas el paquete

pip install wheel

Entramos en la carpeta del proyecto (cd decide) y realizamos las migraciones correspondientes para preparar la base de datos:

Además, será necesario instalar las dependencias correspondientes al panel de control desarrollado con
React. Para ello, primero se deberán tener instaldas las siguientes librerías de js con sus correspondientes
versiones: Node=14.15.0, npm=7.8.0.
Expand All @@ -96,11 +94,11 @@ realizamos la primera migración para preparar la base de datos que utilizaremos
Por último, ya podremos ejecutar el módulos o módulos seleccionados en la configuración de la
siguiente manera:

./manage.py runserver
./manage.py runserver --settings=decide.test_settings

También debemos lanzar el panel de control, para ello dentro de la carpeta decide_panel ejecutamos:

npm start
npm run start:local

## Nuevo panel de administración

Expand Down Expand Up @@ -136,16 +134,21 @@ Abra un nuevo contenedor con el cliente mínimo de open ldap en su equipo, para

```sh
docker run -p 389:389 \
-d carvilgar1us/decideldap
-d carvilgar1us/ldapdecide
```

Para verificar que el contenedor está corriendo correctamente el servicio slapd, pruebe el siguiente
Esta nueva imagen ya contiene un usuario por defecto con credenciales **username = foobar & password = test**.Para verificar que el contenedor está corriendo correctamente el servicio slapd, pruebe el siguiente
comando en su máquina HOST.

```sh
ldapsearch -x -b "dc=decide, dc=org" -H ldap://:389
docker exec -it <CONTAINER_ID> slapcat
```

deberá ver las domain component de decide.org y el miembro foobar ya instanciado.

## Añadir objetos a la organización

Estos pasos son **OPCIONALES** ya que la imagen trae un usuario para utilizar los servicios LDAP.
La consola debe de devolver:
\# extended LDIF
\#
Expand Down Expand Up @@ -173,8 +176,6 @@ description: LDAP administrator

Si es lo que usted ha obtenido entonces puede continuar.

## Añadir objetos a la organización

### Organitational Units

A continuación añadiremos las _Organitational Units_(ou) a nuestra organización,para ello cree un fichero con extensión ldif y ejecútelo con privilegios root **En su maquina HOST**.
Expand Down
16 changes: 8 additions & 8 deletions decide/authentication/templates/welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,32 @@
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
{% if not user.is_authenticated %}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<a id="signinbutton" class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Sign in
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="{% url 'sign_in' %}">LDAP</a></li>
<li><a class="dropdown-item" href="{% url 'sign_in' %}">User/Password</a></li>
<li><a id="ldaplogin" class="dropdown-item" href="{% url 'sign_in' %}">LDAP</a></li>
<li><a id="userlogin" class="dropdown-item" href="{% url 'sign_in' %}">User/Password</a></li>
</ul>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<a id="signupbutton" class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Sign up
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="{% url 'sign_in' %}">User/Password</a></li>
<li><a id="signupuser" class="dropdown-item" href="{% url 'sign_in' %}">User/Password</a></li>
</ul>
</li>
{% endif %}
</ul>
<ul class="navbar-nav ms-auto">
<li class="nav-item mx-0 mx-lg-1"><a class="nav-link py-3 px-0 px-lg-3 rounded" href="#portfolio">Methods</a></li>
<li class="nav-item mx-0 mx-lg-1"><a class="nav-link py-3 px-0 px-lg-3 rounded" href="#about">About</a></li>
<li class="nav-item mx-0 mx-lg-1"><a id="methodsbutton" class="nav-link py-3 px-0 px-lg-3 rounded" href="#portfolio">Methods</a></li>
<li class="nav-item mx-0 mx-lg-1"><a id="aboutbutton" class="nav-link py-3 px-0 px-lg-3 rounded" href="#about">About</a></li>
</ul>
{% if user.is_authenticated %}
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<ul class="navbar-nav ms-auto">
<li class="nav-item"><a class="nav-link" href="{% url 'userlogout' %}">Sign off</a></li>
<li class="nav-item"><a id="signoffbutton" class="nav-link" href="{% url 'userlogout' %}">Sign off</a></li>
<li class="nav-item"><a class="nav-link">Welcome {{ user.first_name }}</a></li>
</ul>
</ul>
Expand Down
163 changes: 131 additions & 32 deletions decide/authentication/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
from rest_framework.test import APITestCase
from django.contrib.auth.models import User
from rest_framework.authtoken.models import Token
# from django.contrib.staticfiles.testing import StaticLiveServerTestCase

# from selenium.common.exceptions import NoSuchElementException
# from selenium.webdriver.common.action_chains import ActionChains
# from selenium import webdriver
# from selenium.webdriver.common.keys import Keys
# from base.tests import BaseTestCase
# from selenium.webdriver.support.ui import WebDriverWait
# from selenium.webdriver.common.by import By
# from selenium.webdriver.support import expected_conditions as EC
# from selenium.webdriver.chrome.options import Options
# from django.test.testcases import LiveServerTestCase
from base import mods

from decide.settings import AUTH_LDAP_SERVER_URI

class AuthTestCase(APITestCase):

Expand Down Expand Up @@ -280,65 +286,117 @@ def test_deleteuser_doesntexist_API(self):
'/authentication/users/100/', format='json')
self.assertEqual(response.status_code, 404)


def test_differentpasswords_register(self):
data = {'username':'testingUser', 'password': '123', 'password2':'456'}
data = {'username': 'testingUser',
'password': '123', 'password2': '456'}
response = self.client.post(
'/authentication/register_user/', data, format='json')
msg = response.json()['error']
self.assertEqual(msg, 'Contraseñas no coinciden')
self.assertEqual(response.status_code, 400)
self.assertEqual(response.status_code, 400)

def test_registeruser_form(self):
data = {'username':'testingUser', 'password': '123', 'password2':'123'}
data = {'username': 'testingUser',
'password': '123', 'password2': '123'}
response = self.client.post(
'/authentication/register_user/', data, format='json')
self.assertEqual(response.status_code, 302)

def test_loginuser_form(self):
data_login = {'username':'testingUser', 'password': '123'}
data_login = {'username': 'testingUser', 'password': '123'}
response = self.client.post(
'/authentication/login_form/', data_login, format='json')
self.assertEqual(response.status_code, 200)

def test_registeruser_existingusername(self):
data_login = {'username':'voter1', 'password': '123456', 'password2':'123456'}
data_login = {'username': 'voter1',
'password': '123456', 'password2': '123456'}
response = self.client.post(
'/authentication/register_user/', data_login, format='json')
msg = response.json()['error']
self.assertEqual(msg, 'Ya existe este nombre de usuario')
self.assertEqual(response.status_code, 400)

#
# TODO: Arreglar tests, estos tests asumen que el sistema ya tiene registrado un usuario 'foobar' en ldap,
# lo cual es erroneo, tiene que registrarse dicho usuario en el setup de los tests
#
# def test_login_ldap_positive(self):
# body_form = {'username': 'foobar', 'password': 'test'}
# response = self.client.post(
# '/authentication/loginLDAP/', body_form, format='json')
# self.assertEqual(response.status_code, 200)
# def test_login_ldap_negative(self):
# body_form = {'username': 'foobar', 'password': 'contrasenyaMal'}
# response = self.client.post(
# '/authentication/loginLDAP/', body_form, format='json')
# self.assertEqual(response.status_code, 400)
def test_login_ldap_positive(self):
body_form = {'username': 'foobar', 'password': 'test'}
response = self.client.post(
'/authentication/loginLDAP/', body_form, format='json')
self.assertEqual(response.status_code, 200)

def test_login_ldap_negative(self):
body_form = {'username': 'foobar', 'password': 'contrasenyaMal'}
response = self.client.post(
'/authentication/loginLDAP/', body_form, format='json')
self.assertEqual(response.status_code, 400)


# class SeleniumLandingPageTestCase(LiveServerTestCase):
# def setUp(self):
# self.base = BaseTestCase()
# self.base.setUp()
# chrome_options = Options()
# chrome_options.add_argument("--window-size=1920,1080")
# chrome_options.headless = True
# self.driver = webdriver.Chrome(chrome_options=chrome_options)

# def tearDown(self):
# self.driver.quit()

# def test_good_redirects_menu(self):

# self.driver.get(f'{self.live_server_url}/authentication/welcome')
# self.driver.find_element_by_id("methodsbutton").click()
# self.assertTrue(self.driver.current_url==f'{self.live_server_url}/authentication/welcome/#portfolio')

# self.driver.find_element_by_id("aboutbutton").click()
# self.assertTrue(self.driver.current_url==f'{self.live_server_url}/authentication/welcome/#about')

# self.driver.find_element_by_class_name("navbar-brand").click()
# self.assertTrue(self.driver.current_url==f'{self.live_server_url}/authentication/welcome/#page-top')

# def test_redirects_signin(self):
# self.driver.get(f'{self.live_server_url}/authentication/welcome')

# self.driver.find_element_by_id("signinbutton").click()
# self.driver.find_element_by_id("ldaplogin").click()
# self.assertTrue(self.driver.current_url==f'{self.live_server_url}/authentication/login_form/')

# self.driver.execute_script("window.history.go(-1)")
# self.driver.find_element_by_id("signinbutton").click()
# self.driver.find_element_by_id("userlogin").click()
# self.assertTrue(self.driver.current_url==f'{self.live_server_url}/authentication/login_form/')

# def test_redirects_signup(self):
# self.driver.get(f'{self.live_server_url}/authentication/welcome')
# self.driver.find_element_by_id("signupbutton").click()
# self.driver.find_element_by_id("signupuser").click()
# self.assertTrue(self.driver.current_url==f'{self.live_server_url}/authentication/login_form/')

# def test_redirects_logout(self):
# self.driver.get(f'{self.live_server_url}/authentication/welcome')
# self.driver.find_element_by_id("signinbutton").click()
# self.driver.find_element_by_id("userlogin").click()
# self.assertTrue(self.driver.current_url==f'{self.live_server_url}/authentication/login_form/')

# self.driver.find_element_by_name('username').send_keys("noadmin")
# self.driver.find_element_by_name('password').send_keys("qwerty",Keys.ENTER)
# self.assertTrue(self.driver.current_url==f'{self.live_server_url}/authentication/bienvenida/')
# self.driver.find_element_by_id("signoffbutton").click()
# self.assertEqual(self.driver.current_url,f'{self.live_server_url}/authentication/userlogout/')

# class SeleniumTestCase(StaticLiveServerTestCase):
# class SeleniumTestCase(LiveServerTestCase):

# def setUp(self):
# self.base = BaseTestCase()
# self.base.setUp()

# options = webdriver.ChromeOptions()
# options.add_argument("--no-sandbox")
# options.add_argument("--disable-dev-shm-usage")
# options.add_argument("--headless")
# # options.add_argument("--no-sandbox")
# # options.add_argument("--disable-dev-shm-usage")
# # options.add_argument("--headless")
# self.driver = webdriver.Chrome(options=options)
# super().setUp()
# super().setUp()

# def tearDown(self):
# super().tearDown()
# self.driver.close()
Expand All @@ -347,7 +405,7 @@ def test_registeruser_existingusername(self):

# def test_register_user(self):
# self.driver.get(f'{self.live_server_url}/authentication/login_form/')
# self.driver.find_elements_by_class_name("controller")[1].click()
# self.driver.find_element(By.CSS_SELECTOR, "p:nth-child(4) > .link").click()

# self.driver.find_element_by_name('username').send_keys("userUser")
# self.driver.find_element_by_name('password').send_keys("asd123")
Expand All @@ -357,12 +415,53 @@ def test_registeruser_existingusername(self):

# self.driver.find_element_by_name('username').send_keys("userUser")
# self.driver.find_element_by_name('password').send_keys("asd123",Keys.ENTER)

# self.assertTrue(self.driver.current_url==f'{self.live_server_url}/authentication/bienvenida/')

# def test_login_success(self):
# def test_login_success(self):
# self.driver.get(f'{self.live_server_url}/authentication/login_form/')
# self.driver.find_element_by_name('username').send_keys("noadmin")
# self.driver.find_element_by_name('password').send_keys("qwerty",Keys.ENTER)

# self.assertTrue(self.driver.current_url==f'{self.live_server_url}/authentication/bienvenida/')

# class SeleniumLDAPViewTestCase(LiveServerTestCase):

# def setUp(self):
# self.base = BaseTestCase()
# self.base.setUp()

# options = webdriver.ChromeOptions()
# # options.add_argument("--no-sandbox")
# # options.add_argument("--disable-dev-shm-usage")
# # options.add_argument("--headless")
# self.driver = webdriver.Chrome(options=options)
# super().setUp()

# def tearDown(self):
# super().tearDown()
# self.driver.close()
# self.driver.quit()
# self.base.tearDown()

# def test_login_ldap_positive(self):
# self.driver.get(f"{self.live_server_url}/authentication/login_form/")
# self.driver.find_element(By.LINK_TEXT, "here").click()
# self.driver.find_element(By.NAME, "username").send_keys("foobar")
# self.driver.find_element(By.NAME, "password").send_keys("test")
# self.driver.find_element(By.NAME, "password").send_keys(Keys.ENTER)

# #Si el usuario inicia sesion de manera exitosa se muestra Welcome usuario en la esquina superior derecha
# self.assertTrue(self.driver.current_url==f'{self.live_server_url}/authentication/loginLDAP/')
# self.assertTrue(self.driver.find_element_by_xpath('/html/body/nav/div/div/ul[3]'))
# self.assertTrue(self.driver.find_element_by_xpath('/html/body/nav/div/div/ul[3]/ul/li[2]/a').get_attribute('innerHTML')=="Welcome foo")

# def test_login_ldap_negative(self):
# self.driver.get(f"{self.live_server_url}/authentication/login_form/")
# self.driver.find_element(By.LINK_TEXT, "here").click()
# self.driver.find_element(By.NAME, "username").send_keys("foobar")
# self.driver.find_element(By.NAME, "password").send_keys("contrasenyaMAl")
# self.driver.find_element(By.NAME, "password").send_keys(Keys.ENTER)

# #Si el usuario inicia sesion de manera exitosa no se muestra Welcome usuario en la esquina superior derecha (mismo xpath que para el test positivo)
# self.assertTrue(self.driver.current_url==f'{self.live_server_url}/authentication/loginLDAP/')
# self.assertRaises(NoSuchElementException, self.driver.find_element_by_xpath, '/html/body/nav/div/div/ul[3]')
2 changes: 1 addition & 1 deletion decide/authentication/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from rest_framework.authtoken.views import obtain_auth_token
from rest_framework import routers

from .views import BienvenidaView, GetUserView, LogoutView, RegisterView, LDAPLogin, SignInView, cerrarsesion, LDAPSignInView,RegisterUserView,landingpage
from .views import BienvenidaView, GetUserView, LogoutView, RegisterView, LDAPLogin, SignInView, cerrarsesion,RegisterUserView,landingpage
from . import views

router = routers.DefaultRouter()
Expand Down
Loading

0 comments on commit 7083e6e

Please sign in to comment.