Skip to content

Commit

Permalink
Merge pull request #7 from daycry/master
Browse files Browse the repository at this point in the history
- Merge
  • Loading branch information
daycry authored Aug 17, 2022
2 parents 7fc1e00 + 8f7893e commit 395de46
Show file tree
Hide file tree
Showing 20 changed files with 136 additions and 187 deletions.
89 changes: 89 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: PHP Tests

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
tests:
name: PHP ${{ matrix.php-versions }} - ${{ matrix.db-platforms }}
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php-versions: ['7.4', '8.0']
db-platforms: ['MySQLi']
mysql-versions: ['5.7']

services:
mysql:
image: mysql:${{ matrix.mysql-versions }}
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: web_service_tests
MYSQL_USER: tests_user
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- uses: actions/checkout@v3

- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
tools: composer
coverage: xdebug
env:
update: true

- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --ansi --no-interaction

- name: Compute coverage option
uses: actions/github-script@v6
id: phpunit-coverage-option
with:
script: 'return "${{ matrix.php-versions }}" == "8.0" ? "" : "--no-coverage"'
result-encoding: string

- name: Test with PHPUnit
run: script -e -c "vendor/bin/phpunit --color=always --exclude-group=auto-review ${{ steps.phpunit-coverage-option.outputs.result }}"

- name: Run Coveralls
if: matrix.php-versions == '8.0'
run: |
composer global require --ansi php-coveralls/php-coveralls:^2.4
php-coveralls --coverage_clover=build/logs/clover.xml -v
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_PARALLEL: true
COVERALLS_FLAG_NAME: PHP ${{ matrix.php-versions }} - ${{ matrix.db-platforms }}
coveralls-finish:
runs-on: ubuntu-latest
needs: [tests]

steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

Rest Server with Doctrine for Codeigniter 4

[![Build Status](https://github.com/daycry/restserver/workflows/PHP%20Tests/badge.svg)](https://github.com/daycry/restserver/actions?query=workflow%3A%22PHP+Tests%22)
[![Coverage Status](https://coveralls.io/repos/github/daycry/restserver/badge.svg?branch=master)](https://coveralls.io/github/daycry/restserver?branch=master)
[![Downloads](https://poser.pugx.org/daycry/restserver/downloads)](https://packagist.org/packages/daycry/restserver)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/daycry/restserver)](https://packagist.org/packages/daycry/restserver)
[![GitHub stars](https://img.shields.io/github/stars/daycry/restserver)](https://packagist.org/packages/daycry/restserver)
[![GitHub license](https://img.shields.io/github/license/daycry/restserver)](https://github.com/daycry/restserver/blob/master/LICENSE)

## Installation via composer

Use the package with composer install
Expand All @@ -28,8 +35,9 @@ $psr4 = [

Run command:

> php spark restserver:publish
> php spark restserver:publish
> php spark settings:publish
> php spark jwt:publish

This command will copy a config file to your app namespace.
Then you can adjust it to your needs. By default file will be present in `app/Config/RestServer.php`.
Expand All @@ -40,7 +48,7 @@ This command create rest server tables in your database.

If you want load and Example Seed you can use this command.

>php spark db:seed Daycry\RestServer\Database\Seeds\ExampleSeeder
> php spark db:seed Daycry\RestServer\Database\Seeds\ExampleSeeder

More information about install doctrine: https://github.com/daycry/doctrine

Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
],
"license": "MIT",
"require": {
"php": ">=7.2 || ^8.0",
"php": ">=7.4 || ^8.0",
"daycry/encryption": "^2.0",
"lcobucci/jwt": "^4.1",
"daycry/settings": "^1.0",
"daycry/class-finder": "^1.0",
"daycry/relations": "^2.0"
"daycry/relations": "^2.0",
"daycry/jwt": "^1.0",
"daycry/class-finder": "^2.0"
},
"require-dev":
{
"phpunit/phpunit": "^9.1",
"codeigniter4/framework": "4.1.2",
"codeigniter4/framework": "^4",
"friendsofphp/php-cs-fixer": "3.6.*",
"mikey179/vfsstream": "^1.6",
"nexusphp/cs-config": "^3.3",
Expand Down
4 changes: 2 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
<!-- Directory containing the front controller (index.php) -->
<const name="PUBLICPATH" value="./public/"/>
<!-- Database configuration -->
<env name="database.tests.hostname" value="localhost" force="true"/>
<!-- <env name="database.tests.hostname" value="localhost" force="true"/> -->
<env name="database.tests.database" value="web_service_tests" force="true"/>
<env name="database.tests.username" value="tests_user" force="true"/>
<env name="database.tests.username" value="root" force="true"/>
<env name="database.tests.password" value="" force="true"/>
<env name="database.tests.DBDriver" value="MySQLi"/>
<env name="database.tests.DBPrefix" value="" force="true"/>
Expand Down
23 changes: 0 additions & 23 deletions src/Config/JWT.php

This file was deleted.

15 changes: 11 additions & 4 deletions src/Libraries/Auth/BaseAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,19 @@ protected function checkLogin($username = null, $password = false)
}

if ($auth_source !== 'library' && $rest_auth === 'bearer') {
$jwtLibrary = new \Daycry\RestServer\Libraries\JWT();
$claims = $jwtLibrary->decode($username);
$jwtLibrary = new \Daycry\JWT\JWT();

if (!$claims || !isset($valid_logins[ $claims->get('data') ])) {
try{
$claims = $jwtLibrary->decode($username);
}catch( \Exception $ex)
{
return false;
//throw \Daycry\RestServer\Exceptions\UnauthorizedException::forInvalidCredentials();
}

if (!$claims || $claims instanceof \Lcobucci\JWT\Validation\RequiredConstraintsViolated || !isset($valid_logins[ $claims->get('data') ])) {
// @codeCoverageIgnoreStart
return false;
// @codeCoverageIgnoreEnd
}

return $claims->get('data');
Expand Down
131 changes: 0 additions & 131 deletions src/Libraries/JWT.php

This file was deleted.

1 change: 0 additions & 1 deletion src/RestServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ protected function _logRequest($authorized = false)
{
// Insert the request into the log table
$logModel = new \Daycry\RestServer\Models\LogModel();
//$logModel->setTableName( $this->_restConfig->configRestLogsTable );

$params = $this->args ? ($this->_restConfig->restLogsJsonParams == true ? \json_encode($this->args) : \serialize($this->args)) : null;
$params = ($params != null && $this->_restConfig->restEncryptLogParams == true) ? $this->encryption->encrypt($params) : $params;
Expand Down
2 changes: 1 addition & 1 deletion tests/Auth/BasicTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Daycry\RestServer\Tests\Auth;
namespace Tests\Auth;

use CodeIgniter\Config\Factories;
use CodeIgniter\HTTP\Request;
Expand Down
Loading

0 comments on commit 395de46

Please # to comment.