PHP Classes

File: tests/cli/start.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   Chronicle   tests/cli/start.php   Download  
File: tests/cli/start.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Chronicle
Append arbitrary data to a storage container
Author: By
Last change: Add test case for #28
Date: 1 year ago
Size: 2,012 bytes
 

Contents

Class file image Download
<?php
declare(strict_types=1);
namespace
ParagonIE\Chronicle\CliTests;

use
ParagonIE\Chronicle\Chronicle;
use
ParagonIE\Sapient\CryptographyKeys\SealingSecretKey;
use
ParagonIE\Sapient\CryptographyKeys\SigningSecretKey;

if (
file_exists(__DIR__ . '/client.json')) {
    exit(
0);
}
if (
file_exists(__DIR__ . '/client-admin.json')) {
    exit(
0);
}

require_once
__DIR__ . '/cli-include.php';

Chronicle::getDatabase()->beginTransaction();

$signingKey = SigningSecretKey::generate();
$publicKey = $signingKey->getPublickey()->getString();

$ret = \file_put_contents(
   
__DIR__ . '/client.json',
    \
json_encode([
       
'secret-key' => $signingKey->getString(),
       
'public-key' => $signingKey->getPublickey()->getString()
    ])
);

if (
is_bool($ret)) {
    echo
'Could not save temporary client', PHP_EOL;
   
Chronicle::getDatabase()->rollBack();
    exit(
255);
}

Chronicle::getDatabase()->insert(
   
'chronicle_clients',
    [
       
'isAdmin' => false,
       
'publicid' => 'CLI-testing-user',
       
'publicKey' => $publicKey
   
]
);

$signingKey = SigningSecretKey::generate();
$publicKey = $signingKey->getPublickey()->getString();

$ret = \file_put_contents(
   
__DIR__ . '/client-admin.json',
    \
json_encode([
       
'secret-key' => $signingKey->getString(),
       
'public-key' => $signingKey->getPublickey()->getString()
    ])
);

$sealingKey = SealingSecretKey::generate();
$publicKey = $sealingKey->getPublickey()->getString();

$ret = \file_put_contents(
   
__DIR__ . '/sealing.json',
    \
json_encode([
       
'secret-key' => $sealingKey->getString(),
       
'public-key' => $sealingKey->getPublickey()->getString()
    ])
);

if (
is_bool($ret)) {
    echo
'Could not save temporary client', PHP_EOL;
   
Chronicle::getDatabase()->rollBack();
    exit(
255);
}

Chronicle::getDatabase()->insert(
   
'chronicle_clients',
    [
       
'isAdmin' => true,
       
'publicid' => 'CLI-admin-user',
       
'publicKey' => $publicKey
   
]
);

Chronicle::getDatabase()->commit();