Skip to content

Commit

Permalink
PHP-tests fixes (cossacklabs#285)
Browse files Browse the repository at this point in the history
* php tests with composer setup

* php tests fix

* fix tests

* Force env init before tests

* fix session in extension

* Makefiles for php-tests

* small readme fix

* Makefiles for php-tests

* apt-get php5-dev

* Circle-ci php env

* Circle-ci php env

* Make for php-tests

* Make for php-tests

* Circle-ci config for phpize link

* Circle-ci config for php-config link

* fix for php test

* Circle build setting push

* Isolate python test

* Revert python test isolation

* explicitly use python2
temporarily comment coverage calculation

* force rebuild

* fix setuptools error

* fix editor newline

* fix gcov usage

* setup python3 version

* force rebuild

* fix installing python
  • Loading branch information
mozhmike authored and Lagovas committed Jan 25, 2018
1 parent d60a8bb commit d057baf
Show file tree
Hide file tree
Showing 16 changed files with 468 additions and 380 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ __pycache__/
tests/phpthemis/vendor
tests/phpthemis/composer.json
tests/phpthemis/composer.phar
tests/phpthemis/composer.lock
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ else
VERSION = $(shell date -I | sed s/-/_/g)
endif

PHP_VERSION := $(shell php --version 2>/dev/null)
PHP_VERSION := $(shell php -r "echo PHP_MAJOR_VERSION;" 2>/dev/null)
RUBY_GEM_VERSION := $(shell gem --version 2>/dev/null)
GO_VERSION := $(shell go version 2>&1)
NPM_VERSION := $(shell npm --version 2>/dev/null)
Expand Down Expand Up @@ -405,7 +405,13 @@ uninstall: phpthemis_uninstall rubythemis_uninstall themispp_uninstall
@echo -n "themis uninstall "
@$(BUILD_CMD_)

phpthemis_install: CMD = cd src/wrappers/themis/php && phpize && ./configure && make install
ifeq ($(PHP_VERSION),5)
PHP_FOLDER = php
else
PHP_FOLDER = php7
endif

phpthemis_install: CMD = cd src/wrappers/themis/$(PHP_FOLDER) && phpize && ./configure && make install

phpthemis_install: install
ifdef PHP_VERSION
Expand Down
12 changes: 10 additions & 2 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ machine:
# add define that turn off one nist test (tests/soter/soter_rand_test.c:190) that always fail on ci machine but ok on real machine
CFLAGS: "-DCIRICLE_TEST"
BORINGSSL_PATH: "$HOME/boringssl"
php:
5.6.17

## Customize dependencies
dependencies:
Expand All @@ -22,8 +24,10 @@ dependencies:
- "~/boringssl"

pre:
- sudo apt-get update && sudo DEBIAN_FRONTEND=noninteractive apt-get -y install php5 cmake libssl-dev python3 python3-setuptools ruby ninja-build lcov build-essential libc6-dbg
- sudo ln -sf /usr/bin/gcov-4.9 /usr/bin/gcov
- sudo apt-get update && sudo DEBIAN_FRONTEND=noninteractive apt-get -y install cmake libssl-dev python python-setuptools python3-setuptools ruby ninja-build lcov build-essential libc6-dbg
- sudo ln -sf /usr/bin/gcov-4.8 /usr/bin/gcov
- sudo ln -sf /opt/circleci/.phpenv/shims/phpize /usr/bin/phpize
- sudo ln -sf /opt/circleci/.phpenv/shims/php-config /usr/bin/php-config
- if [ ! -d $GOROOT ]; then cd $HOME && wget https://storage.googleapis.com/golang/go1.6.2.linux-amd64.tar.gz && tar xf go1.6.2.linux-amd64.tar.gz; fi
- gem install coveralls-lcov
- go get github.com/mattn/goveralls
Expand All @@ -38,10 +42,14 @@ dependencies:

override:
- git submodule update --init
# setup explicitly versions of python to correctly run scripts with python3 name
- make
- make JAVA_HOME=/usr/lib/jvm/default-java themis_jni
- sudo make install
- sudo make themispp_install
- pyenv global 2.7.12 3.4.4
# set python from pyenv global accessible because we install with sudo
- sudo rm /usr/bin/python2 /usr/bin/python3 && sudo ln -s `which python2` /usr/bin/python2 && sudo ln -s `which python3` /usr/bin/python3
- sudo make pythemis_install
- sudo make rubythemis_install
- sudo make phpthemis_install
Expand Down
30 changes: 16 additions & 14 deletions src/wrappers/themis/php7/php_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ ssize_t receive_callback(uint8_t *data, size_t data_length, void *user_data){
return -1;
}

typedef struct themis_secure_session_object_t {
secure_session_t *session;
zend_object std;
} themis_secure_session_object;

static inline themis_secure_session_object * get_session_object(zend_object *obj) {
return (themis_secure_session_object*)((char *)obj - XtOffsetOf(themis_secure_session_object, std));
}

#define Z_SESSION_P(zv) get_session_object(Z_OBJ_P(zv));


int get_public_key_by_id_callback(const void *id, size_t id_length, void *key_buffer, size_t key_buffer_length, void *user_data){
// unused
(void)(user_data);
Expand All @@ -38,19 +50,15 @@ int get_public_key_by_id_callback(const void *id, size_t id_length, void *key_bu
return THEMIS_SUCCESS;
}

typedef struct themis_secure_session_object_t {
secure_session_t *session;
zend_object std;
} themis_secure_session_object;

void themis_secure_session_free_storage(void *object TSRMLS_DC)
{
themis_secure_session_object *obj = (themis_secure_session_object *)object;
secure_session_destroy(obj->session);
themis_secure_session_object *obj = get_session_object(object);
secure_session_t* session = obj->session;
secure_session_destroy(session);

zend_hash_destroy(obj->std.properties);
FREE_HASHTABLE(obj->std.properties);
efree(obj);
efree(object);
}

zend_object_handlers themis_secure_session_object_handlers;
Expand All @@ -71,12 +79,6 @@ zend_object* themis_secure_session_create_handler(zend_class_entry *type TSRMLS_
return &obj->std;
}

static inline themis_secure_session_object * get_session_object(zend_object *obj) {
return (themis_secure_session_object*)((char *)obj - XtOffsetOf(themis_secure_session_object, std));
}

#define Z_SESSION_P(zv) get_session_object(Z_OBJ_P(zv));

PHP_METHOD(themis_secure_session, __construct){
secure_session_t *session = NULL;
char* id;
Expand Down
5 changes: 0 additions & 5 deletions tests/phpthemis/composer-php5.6.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{
"name": "tests/phpthemis/php-5.6",
"description": "Some stuff for tests",
"autoload": {
"classmap": [
"src/"
]
},
"require": {
"php": "^5.6",
"phpunit/phpunit": "^5"
Expand Down
5 changes: 0 additions & 5 deletions tests/phpthemis/composer-php7.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{
"name": "tests/phpthemis/php-7",
"description": "Some stuff for tests",
"autoload": {
"classmap": [
"src/"
]
},
"require": {
"php": "^7",
"phpunit/phpunit": "^6"
Expand Down
Empty file modified tests/phpthemis/composer-setup.sh
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion tests/phpthemis/init_env-php5.6.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash -e

rm composer.json
rm -f composer.json
ln -s composer-php5.6.json composer.json
php composer.phar update
2 changes: 1 addition & 1 deletion tests/phpthemis/init_env-php7.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash -e

rm composer.json
rm -f composer.json
ln -s composer-php7.json composer.json
php composer.phar update
2 changes: 1 addition & 1 deletion tests/phpthemis/php.ini
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ default_socket_timeout = 60
;
; ... or under UNIX:
;
extension=phpthemis.so
extension=./phpthemis.so
;
; ... or with a path:
;
Expand Down
22 changes: 18 additions & 4 deletions tests/phpthemis/run_tests.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
#!/bin/bash -e

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $DIR
PHPVERSION=`php -r "echo PHP_MAJOR_VERSION;"`


if [ ! -f ./composer.phar ]; then
bash ./composer-setup.sh
fi

if [ $PHPVERSION = 7 ]; then
bash ./init_env-php7.sh
else
bash ./init_env-php5.6.sh
fi

echo -e "\n >>>> secure cell tests <<<<\\n"
./vendor/phpunit/phpunit/phpunit scell_test.php
php -c php.ini ./vendor/phpunit/phpunit/phpunit scell_test.php
echo -e "\n >>>> secure message tests <<<<\n"
./vendor/phpunit/phpunit/phpunit smessage_test.php
php -c php.ini ./vendor/phpunit/phpunit/phpunit smessage_test.php
echo -e "\n >>>> secure token tests <<<<\n"
# todo:
./vendor/phpunit/phpunit/phpunit ssession_test.php
php -c php.ini ./vendor/phpunit/phpunit/phpunit ssession_test.php
Loading

0 comments on commit d057baf

Please sign in to comment.