Skip to content

Commit

Permalink
ci: switch to github actions (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
willdurand authored Jan 30, 2022
1 parent 9b23d3b commit 4e9c366
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 41 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: ci

on:
pull_request:
push:
branches:
- master

jobs:
phpunit:
runs-on: "ubuntu-20.04"

strategy:
fail-fast: false
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"

steps:
- uses: actions/checkout@v2

- name: "Install PHP ${{ matrix.php-version }}"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
coverage: "pcov"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"

- name: "Run PHPUnit"
run: "vendor/bin/simple-phpunit --coverage-text"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/vendor/
bin/
composer.lock
.phpunit.result.cache
41 changes: 14 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,37 @@
JsonpCallbackValidator
======================
# JsonpCallbackValidator

[![Build
Status](https://travis-ci.org/willdurand/JsonpCallbackValidator.png?branch=master)](https://travis-ci.org/willdurand/JsonpCallbackValidator)
[![GitHub Actions](https://github.com/willdurand/JsonpCallbackValidator/workflows/ci/badge.svg)](https://github.com/willdurand/JsonpCallbackValidator/actions?query=workflow%3A%22ci%22+branch%3Amaster)
[![Total
Downloads](https://poser.pugx.org/willdurand/jsonp-callback-validator/downloads.png)](https://packagist.org/packages/willdurand/jsonp-callback-validator)
[![Latest Stable
Version](https://poser.pugx.org/willdurand/jsonp-callback-validator/v/stable.png)](https://packagist.org/packages/willdurand/jsonp-callback-validator)


**JsonpCallbackValidator** allows you to **validate a JSONP callback** in order
to prevent XSS attacks.


Usage
-----
## Usage

```php
$validator = new \JsonpCallbackValidator();

$validator->validate('JSONP.callback');
$validator->validate("JSONP.callback");
// returns `true`

$validator->validate('(function xss(x){evil()})');
$validator->validate("(function xss(x){evil()})");
// returns `false`
```

Or as a static method:

```php
\JsonpCallbackValidator::validate('JSONP.callback');
\JsonpCallbackValidator::validate("JSONP.callback");
// returns `true`

\JsonpCallbackValidator::validate('(function xss(x){evil()})');
\JsonpCallbackValidator::validate("(function xss(x){evil()})");
// returns `false`
```

Installation
------------
## Installation

The recommended way to install JsonpCallbackValidator is through
[Composer](https://getcomposer.org/):
Expand All @@ -46,33 +40,26 @@ The recommended way to install JsonpCallbackValidator is through
$ composer require willdurand/jsonp-callback-validator
```

Unit Tests
----------
## Unit Tests

Setup the test suite using Composer:

$ composer install

Run it using PHPUnit:

$ ./vendor/bin/phpunit

$ ./vendor/bin/simple-phpunit

Contributing
------------
## Contributing

See [CONTRIBUTING](CONTRIBUTING.md) file.

## Credits

Credits
-------

* Erik Eng ([@ptz0n](https://github.com/ptz0n)) for [his
- Erik Eng ([@ptz0n](https://github.com/ptz0n)) for [his
Gist](https://gist.github.com/ptz0n/1217080)


License
-------
## License

JsonpCallbackValidator is released under the MIT License. See the bundled
LICENSE file for details.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"license": "MIT",
"authors": [
{
"name": "William DURAND",
"email": "william.durand1@gmail.com"
"name": "William Durand",
"email": "will+git@drnd.me"
}
],
"require": {
"php": "^5.3 || ^7.0"
"php": ">=7.1.0"
},
"require-dev": {
"phpunit/phpunit": "^4.5 || ^5.7"
"symfony/phpunit-bridge": "^5.0"
},
"autoload": {
"psr-0": { "JsonpCallbackValidator": "src/" }
Expand Down
16 changes: 8 additions & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>
<testsuites>
<testsuite name="CallbackValidator Test Suite">
<testsuite name="JsonpCallbackValidator Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
<coverage>
<include>
<directory>./src/JsonpCallbackValidator/</directory>
</include>
</coverage>
</phpunit>
4 changes: 3 additions & 1 deletion tests/JsonpCallbackValidatorTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

class JsonpCallbackValidatorTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase as PHPUnitTestCase;

class JsonpCallbackValidatorTest extends PHPUnitTestCase
{
const IS_VALID = true;

Expand Down

0 comments on commit 4e9c366

Please sign in to comment.