Skip to content

Commit

Permalink
Merge pull request #16 from genecommerce/tests
Browse files Browse the repository at this point in the history
Add basic circleci verification tests
  • Loading branch information
convenient authored Jul 17, 2024
2 parents 7b9e50e + 9d20c9b commit 1628102
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 1 deletion.
32 changes: 32 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: 2.1

jobs:
build:
machine:
image: default
steps:
- checkout
- run:
name: Verify Architecture
command: uname -m
- run:
name: Log docker version
command: |
docker --version && docker compose version
- run:
name: Set up magento and run tests
command: |
INSTALL_LOC=$(pwd)
cd /tmp/
git clone https://github.com/AmpersandHQ/magento-docker-test-instance --branch 0.1.21
cd magento-docker-test-instance
CURRENT_EXTENSION="$INSTALL_LOC" FULL_INSTALL=1 ./bin/mtest-make 2-4-6-p3
./bin/mtest 'cp vendor/gene/module-encryption-key-manager/dev/test.sh .'
./bin/mtest 'chmod +x ./test.sh'
./bin/mtest './test.sh'
workflows:
version: 2
build_and_test:
jobs:
- build
2 changes: 1 addition & 1 deletion Console/ReencryptColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
declare(strict_types=1);
namespace Gene\EncryptionKeyManager\Console;

use Composer\Console\Input\InputArgument;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\App\CacheInterface;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\Encryption\EncryptorInterface;
use Magento\Framework\Console\Cli;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand Down
19 changes: 19 additions & 0 deletions dev/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
These tests are not what we would like long term, but for a quick win they have been added as a shell script.

To run the tests
```bash
# Get set up with the module
git clone https://github.com/genecommerce/module-encryption-key-manager
git clone https://github.com/AmpersandHQ/magento-docker-test-instance --branch 0.1.21
cd magento-docker-test-instance

# Install magento
CURRENT_EXTENSION="../module-encryption-key-manager" FULL_INSTALL=1 ./bin/mtest-make 2-4-6-p3

# Setup tests
./bin/mtest 'cp vendor/gene/module-encryption-key-manager/dev/test.sh .'
./bin/mtest 'chmod +x ./test.sh'

# Run tests
./bin/mtest './test.sh'
```
82 changes: 82 additions & 0 deletions dev/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/bash
set -euo pipefail
err_report() {
echo "Error on line $1"
}
trap 'err_report $LINENO' ERR

URL='http://0.0.0.0:1234/'
CURRENT_TIMESTAMP=$(date +%s)
ADMIN="adminuser$CURRENT_TIMESTAMP"
PASSWORD='password123'

echo "Stubbing in some test data"
vendor/bin/n98-magerun2 --version
vendor/bin/n98-magerun2 admin:user:create --no-interaction --admin-user "$ADMIN" --admin-email "example$CURRENT_TIMESTAMP@example.com" --admin-password $PASSWORD --admin-firstname adminuser --admin-lastname adminuser
vendor/bin/n98-magerun2 config:store:set zzzzz/zzzzz/zzzz abc123 --encrypt
FAKE_RP_TOKEN=$(vendor/bin/n98-magerun2 dev:encrypt 'abc123')
vendor/bin/n98-magerun2 db:query "update admin_user set rp_token='$FAKE_RP_TOKEN' where username='$ADMIN'"
echo "Generated FAKE_RP_TOKEN=$FAKE_RP_TOKEN and assigned to $ADMIN"

echo "";echo "";

echo "Verifying commands need to use --force"
if ! php bin/magento gene:encryption-key-manager:generate | grep -q 'Run with --force'; then
echo "PASS: generate needs to run with force"
fi
if ! php bin/magento gene:encryption-key-manager:invalidate | grep -q 'Run with --force'; then
echo "PASS: invalidate needs to run with force"
fi
if ! php bin/magento gene:encryption-key-manager:reencrypt-unhandled-core-config-data | grep -q 'Run with --force'; then
echo "PASS: reencrypt-unhandled-core-config-data needs to run with force"
fi
if ! php bin/magento gene:encryption-key-manager:reencrypt-column admin_user user_id rp_token --force | grep -q 'Run with --force'; then
echo "PASS: reencrypt-column needs to run with force"
fi
echo "";echo "";

echo "Verifying you cannot invalidate with only 1 key"
if ! php bin/magento gene:encryption-key-manager:invalidate --force | grep -q 'Cannot invalidate when there is only one key'; then
echo "PASS: You cannot invalidate with only 1 key"
fi
echo "";echo "";

echo "Generating a new encryption key"
php bin/magento gene:encryption-key-manager:generate --force
echo "PASS"
echo "";echo "";

echo "Running reencrypt-unhandled-core-config-data"
php bin/magento gene:encryption-key-manager:reencrypt-unhandled-core-config-data --force > unhandled.txt
cat unhandled.txt
grep -q 'zzzzz/zzzzz/zzzz' unhandled.txt
grep -q 'abc123' unhandled.txt
echo "PASS"
echo "";echo "";
echo "Running reencrypt-unhandled-core-config-data - again to verify it was all processed"
php bin/magento gene:encryption-key-manager:reencrypt-unhandled-core-config-data --force | grep --context 999 'No old entries found'
echo "PASS"
echo "";echo "";

echo "Running reencrypt-column"
php bin/magento gene:encryption-key-manager:reencrypt-column admin_user user_id rp_token --force > column.txt
cat column.txt
grep -q "$FAKE_RP_TOKEN" column.txt
grep -q abc123 column.txt
echo "PASS"
echo "";echo "";
echo "Running reencrypt-column - again to verify it was all processed"
php bin/magento gene:encryption-key-manager:reencrypt-column admin_user user_id rp_token --force | grep --context 999 'No old entries found'
echo "PASS"
echo "";echo "";

echo "Running invalidate"
php bin/magento gene:encryption-key-manager:invalidate --force
grep -q invalidated_key app/etc/env.php
php bin/magento gene:encryption-key-manager:invalidate --force | grep --context 999 'No further keys need invalidated'
echo "PASS"
echo "";echo "";

echo "A peek at the env.php"
grep -A10 "'crypt' =>" app/etc/env.php
echo "DONE"

0 comments on commit 1628102

Please sign in to comment.