Skip to content

Commit 3190329

Browse files
committed
Tests completed.
1 parent db462b4 commit 3190329

File tree

74 files changed

+5788
-1904
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+5788
-1904
lines changed

.dockerignore

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,2 @@
11
.idea/
2-
app/logs/*.log
3-
composer.lock
4-
db/sql/data.txt
5-
db/sql/out.txt
6-
public/requests.log
7-
tests/_output/
8-
.DS_Store
9-
deploy/servers.yml
10-
.env.testing
2+
.DS_Store

.gitignore

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
.idea/
22
vendor/
33
app/logs/*.log
4-
db/sql/data.txt
5-
db/sql/out.txt
64
public/requests.log
75
tests/_output/
86
.DS_Store
9-
deploy/servers.yml
10-
tests/_support/_generated/ApiTesterActions.php
117
app/env/.env
128
app/env/.env.test
13-
app/env/.env.staging
9+
keys/public.key
10+
keys/private.key

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# [1.0.0](https://github.com/tegaphilip/padlock/releases/tag/v1.0.0) (2018-08-10)
2+
- Initial release

CONDUCT.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Contributor Code of Conduct
2+
3+
As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4+
5+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
6+
7+
Examples of unacceptable behavior by participants include:
8+
9+
* The use of sexualized language or imagery
10+
* Personal attacks
11+
* Trolling or insulting/derogatory comments
12+
* Public or private harassment
13+
* Publishing other's private information, such as physical or electronic addresses, without explicit permission
14+
* Other unethical or unprofessional conduct.
15+
16+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
17+
18+
This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community in a direct capacity. Personal views, beliefs and values of individuals do not necessarily reflect those of the organisation or affiliated individuals and organisations.
19+
20+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
21+
22+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)

CONTRIBUTING.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Contributing
2+
3+
Contributions are **welcome** and will be fully **credited**.
4+
5+
We accept contributions via Pull Requests on [Github](https://github.com/cottacush/phalcon-utils).
6+
7+
8+
## Pull Requests
9+
10+
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).
11+
12+
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
13+
14+
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
15+
16+
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.
17+
18+
- **Create feature branches** - Don't ask us to pull from your master branch.
19+
20+
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
21+
22+
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
23+
24+
25+
## Running Tests
26+
27+
``` bash
28+
$ composer test
29+
```
30+
31+
32+
**Happy coding**!

Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM mileschou/phalcon:7.0-apache
22

33
MAINTAINER Tega Oghenekohwo <[email protected]>
44

5-
COPY /docker/php/php.ini /usr/local/etc/php/
5+
#COPY /docker/php/php.ini /usr/local/etc/php/
66

77
COPY /docker/php/000-default.conf /etc/apache2/sites-available/000-default.conf
88

@@ -11,18 +11,18 @@ RUN a2enmod rewrite
1111

1212
RUN apt-get update && apt-get install -y zlib1g-dev git && \
1313
docker-php-ext-install zip pdo_mysql && \
14-
1514
#Download composer
1615
curl -sS https://getcomposer.org/installer | php && \
1716
mv composer.phar /usr/local/bin/composer && \
18-
mkdir -p /var/www/html/hocaboo-auth
17+
mkdir -p /var/www/html/padlock
1918

19+
#included for running mysql command line scripts during tests
2020
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install mysql-server
2121

2222
# Copy Source Code
23-
COPY . /var/www/html/hocaboo-auth/
23+
COPY . /var/www/html/padlock/
2424

25-
WORKDIR /var/www/html/hocaboo-auth
25+
WORKDIR /var/www/html/padlock
2626

2727
#install composer dependencies
2828
RUN composer install

README.md

Lines changed: 117 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,140 @@
1-
ELECTION APP
2-
===========
3-
Election App
1+
# Padlock, Phalcon Authentication Server
42

5-
Features
6-
--------
7-
* ...
3+
[![Latest Version on Packagist][ico-version]][link-packagist]
4+
[![Software License][ico-license]](LICENSE.md)
5+
[![Total Downloads][ico-downloads]][link-downloads]
86

7+
Padlock is a docker-based phalcon authentication server built on top of the [PHP OAuth 2.0 Server](https://github.com/thephpleague/oauth2-server)
98

10-
Contributors
9+
Setting Up
1110
------------
12-
* Tega Oghenekohwo <[email protected]>
11+
* Add the entries `padlock.local` and `padlock-test.local` and map to `127.0.0.1` in your `/etc/hosts` file
1312

13+
* Ensure you have docker installed
1414

15-
Requirements
16-
------------
17-
* [Phalcon 3.3](https://docs.phalconphp.com/en/latest/reference/install.html)
18-
* [Composer](https://getcomposer.org/doc/00-intro.md#using-composer)
15+
* Make a copy of `.env.sample` to `.env` in the `app/env/` directory and replace the values.
16+
17+
* You can generate the `ENCRYPTION_KEY` environment variable by running
18+
`php -r "echo base64_encode(random_bytes(40)) . PHP_EOL;"` on the command line
19+
20+
* cd into the `keys` directory and generate your public and private keys like so: `openssl genrsa -out private.key 2048`
21+
then `openssl rsa -in private.key -pubout -out public.key`. These are needed for encrypting and decrypting tokens
22+
23+
* Feel free to change the port mappings in `docker-compose.yml` if you already have services running on ports `8899` for
24+
the phalcon app and `33066` for the mysql server
25+
26+
* Run the app like this `./bin/start.sh` or run `docker-compose up -d`
27+
28+
* Login to mysql using the credentials host:127.0.0.1, username: root, password:root, port: 33066
29+
30+
* Create two databases: `padlock_db` and `padlock_test_db` and import the sql file found in `app/db/padlock.sql` into
31+
both databases
32+
33+
Try it out
34+
==========
35+
36+
Requesting a Token
37+
------------------
38+
39+
1. Password Grant Flow: Send a `POST` request to `http://padlock.local/api/v1/oauth/token` with the following parameters:
40+
- client_id: test
41+
- client_secret: secret
42+
- grant_type: password
43+
- username: abc
44+
- password: abc
45+
46+
NOTE: This grant returns an access token and a refresh token
47+
48+
2. Client Credentials Grant Flow: Send a `POST` request to `http://padlock.local/api/v1/oauth/token` with the following parameters:
49+
- client_id: test
50+
- client_secret: secret
51+
- grant_type: client_credentials
52+
53+
NOTE: This grant returns only an access token
54+
55+
3. Refresh Token Grant: Send a `POST` request to `http://padlock.local/api/v1/oauth/token` with the following parameters:
56+
- client_id: test
57+
- client_secret: secret
58+
- grant_type: refresh_token
59+
- refresh_token: value gotten from any flow that returns a refresh token (e.g password grant flow)
60+
61+
NOTE: This grant returns another access token and refresh token and invalidates/revokes the previous ones
62+
63+
4. Implicit Grant: Send a `GET` request to `http://padlock.local/api/v1/oauth/authorize` with the following parameters:
64+
- client_id: test
65+
- response_type: token
66+
- state: a random string (optional)
67+
- redirect_uri: http://www.test.com (optional)
68+
69+
NOTE: This grant returns an access token immediately. It does not return a refresh token.
70+
71+
5. Authorization Code Grant: Send a `GET` request to `http://padlock.local/api/v1/oauth/authorize` with the following parameters:
72+
- client_id: test
73+
- response_type: code
74+
- state: a random string (optional)
75+
- redirect_uri: http://www.test.com (optional)
76+
77+
NOTE: This grant returns an authorization code that is then used to request for a token by sending a `POST`
78+
request to the endpoint `http://padlock.local/api/v1/oauth/token` with the following parameters:
79+
- client_id: test
80+
- client_secret: secret
81+
- grant_type: authorization_code
82+
- code: value gotten from the get request
83+
- redirect_uri: http://www.test.com (optional)
84+
85+
Validating a Token
86+
------------------
87+
Send a `POST` request to `http://padlock.local/api/v1/oauth/token/validate` with an `Authorization` header whose value is
88+
`Bearer {access_token}`
89+
1990

91+
Running Tests
92+
-------------
2093

21-
Installation
22-
------------
94+
* Make a copy of `.env.sample` to `.env.test` in the `app/env/` directory and replace the values.
2395

24-
Setup Environment Variables
25-
---------------------------
26-
Make a copy of .env.sample to .env in the env directory and replace the values.
96+
* Login to the app container using `./bin/login.sh` or run `docker exec -it padlock_app bash`
2797

98+
* Execute unit tests `./unit-test.sh` (uses [PHPUnit](https://phpunit.de/))
2899

29-
Set Up Using Docker
30-
-------------------------------
100+
* Run integration tests using `./integration-test.sh` (uses [Codeception](https://codeception.com/))
31101

32-
* `php vendor/bin/phinx migrate`
102+
## Install
33103

34-
* Ensure you have docker installed
104+
Via Composer
35105

36-
* Create a clone of the `.env.testing.sample` file and name it `.env` and replace the values of the variables
106+
``` bash
107+
$ composer require tegaphilip/padlock
108+
```
37109

38-
* Login to mysql using the credentials host:127.0.0.1, username: root, password:root, port: 32800
110+
## Change log
39111

40-
* Create two databases: `election_app` and `election_app_test`
112+
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
41113

42-
* Run migrations `php vendor/bin/phinx migrate`
43114

44-
Run the following to import states, etc from Excel File (If any of the scripts fail, try without the underscore)
115+
## Contributing
45116

46-
* `DB_HOST=mysql DB_USER=root DB_PASSWORD=root DB_NAME=election_app php app/cli.php states_import import`
47-
* `DB_HOST=mysql DB_USER=root DB_PASSWORD=root DB_NAME=election_app php app/cli.php lgas_import import`
48-
* `DB_HOST=mysql DB_USER=root DB_PASSWORD=root DB_NAME=election_app php app/cli.php wards_import import`
49-
* `DB_HOST=mysql DB_USER=root DB_PASSWORD=root DB_NAME=election_app php app/cli.php stations_import import`
50-
* `DB_HOST=mysql DB_USER=root DB_PASSWORD=root DB_NAME=election_app php app/cli.php inec_lgas_import import`
51-
* `DB_HOST=mysql DB_USER=root DB_PASSWORD=root DB_NAME=election_app php app/cli.php inec_wards_import import`
52-
* `DB_HOST=mysql DB_USER=root DB_PASSWORD=root DB_NAME=election_app php app/cli.php inec_stations_import import`
117+
Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.
53118

54-
Running Tests
55-
-------------
119+
## Security
120+
121+
If you discover any security related issues, please email <[email protected]> instead of using the issue tracker.
122+
123+
## Credits
124+
125+
- [Tega Oghenekohwo](https://github.com/tegaphilip)
126+
- [Adeyemi Olaoye](https://github.com/yemexx1)
127+
- [All Contributors][link-contributors]
128+
129+
130+
[ico-version]: https://img.shields.io/packagist/v/tegaphilip/padlock.svg?style=flat-square
131+
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
132+
[ico-downloads]: https://img.shields.io/packagist/dt/tegaphilip/padlock.svg?style=flat-square
133+
134+
[link-packagist]: https://packagist.org/packages/tegaphilip/padlock
135+
[link-code-quality]: https://scrutinizer-ci.com/g/tegaphilip/padlock
136+
[link-downloads]: https://packagist.org/packages/tegaphilip/padlock
137+
[link-contributors]: ../../contributors
56138

57-
Create a clone of the `.env.testing.sample` file and name it `.env.testing` and replace the values of the variables
58-
59-
* Create a test database `election_app_test`
60-
61-
* Execute tests using `./runtest.sh` to run all tests or `./runtest.sh {testName}` to run a particular test. E.g `./runtest.sh UserCest`
62-
63-
php vendor/bin/phinx create StateMigration
64-
65-
Deploying on Staging
66-
--------------------
67-
* sudo apt-get update
68-
* Install apache with `sudo apt-get install apache2`
69-
* Get phalcon repository with `curl -s https://packagecloud.io/install/repositories/phalcon/stable/script.deb.sh | sudo bash`
70-
* Install phalcon with `sudo apt-get install php7.0-phalcon`
71-
* Check Phalcon Version with `php -r "echo Phalcon\Version::get();"`
72-
* sudo apt-get install php7.0-mbstring
73-
* sudo apt-get install php7.0-curl
74-
* sudo apt-get install php7.0-xml
75-
* sudo apt-get install php7.0-mysql
76-
* sudo apt-get install php7.1-phalcon
77-
* https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-16-04
78-
* https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-in-ubuntu-16-04
79-
* extensions /usr/lib/php/20160303
80-
* INI APACHE cat /etc/php/7.1/apache2/php.ini
81-
* ADDITIONAL INI APACHE ls -al /etc/php/7.1/apache2/conf.d
82-
* INI CLI cat /etc/php/7.1/cli/php.ini
83-
* ADDITIONAL INI CLI ls -al /etc/php/7.1/cli/conf.d
84-
* sudo find / -iname 'phalcon.so' -exec rm -f {} \; // remove
85-
* sudo find / -iname 'phalcon.so'
86-
87-
sudo apt-get install -y php7.1 libapache2-mod-php7.1 php7.1-cli php7.1-common php7.1-mbstring php7.1-gd php7.1-intl php7.1-xml php7.1-mysql php7.1-mcrypt php7.1-zip
88-
sudo apt-get install -y php7.1-curl
89-
90-
* For some reason addExistence Validation causes things to fail on staging server (AWS, DO, etc)
91-
92-
* Run import tasks
93139

94140

0 commit comments

Comments
 (0)