Skip to content

Commit ec6dd5b

Browse files
committed
Add explicit administration schema migration and contract test
1 parent 3ad747c commit ec6dd5b

4 files changed

Lines changed: 113 additions & 0 deletions

File tree

‎.github/workflows/webauthn-dependencies.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ jobs:
2525
with:
2626
name: composer-lock-php-${{ matrix.php }}
2727
path: composer.lock
28+
29+
- run: php -l htdocs/application/migrations/20261129000001_admin_credentials.php
30+
- run: php tests/admin-schema-smoke.php

‎doc/admin-passkeys.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ Reuse existing CodeIgniter conventions after inspecting the actual migration mec
1010

1111
## Contribution requirements
1212
Use maintained dependencies, review licences and advisories, keep secrets and personal data out of Git, preserve existing behaviour and data, document migration and rollback, test changes and maintain a current handover. Aim for WCAG 2.2 AA and lightweight mobile-first UI. No production details or sensitive security findings in this public repository.
13+
14+
## Schema checkpoint — 29 November 2026
15+
Added explicit CodeIgniter timestamp migration 20261129000001 defining admin_users, admin_credentials and admin_audit_log. No migration activation, accounts, credentials or authentication endpoints. Users default disabled. Credential hash is SHA-256 of raw credential ID (repository implementation pending); credential_json will hold library-serialised public credential metadata, never a private key. Identifier and credential ownership validation, revocation enforcement, concurrent updates, username uniqueness policy and audit retention remain to be implemented. Migration down deliberately refuses destructive rollback. Existing migration configuration remains disabled. The mock DBForge contract test checks declared schema only; real MariaDB migration, prefix, repeat execution, partial-failure recovery, existing schema preservation and other supported drivers are unverified and required before release. Lockfile commit remains outstanding. No production changes. Next: verify CI, implement real database integration tests and credential repository using the WebAuthn serializer, then enrolment and authentication. No release version change for this unreleased prototype.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
defined('BASEPATH') OR exit('No direct script access allowed');
3+
4+
/**
5+
* Additive administration schema. Explicit migration only.
6+
* No accounts, credentials or access grants are created here.
7+
*/
8+
class Migration_Admin_credentials extends CI_Migration
9+
{
10+
public function up()
11+
{
12+
$this->load->dbforge();
13+
$this->dbforge->add_field(array(
14+
'id' => array('type' => 'CHAR', 'constraint' => 64),
15+
'username' => array('type' => 'VARCHAR', 'constraint' => 128),
16+
'enabled' => array('type' => 'INT', 'default' => 0),
17+
'created_at' => array('type' => 'BIGINT'),
18+
));
19+
$this->dbforge->add_key('id', TRUE);
20+
if (!$this->dbforge->create_table('admin_users', TRUE)) {
21+
throw new RuntimeException('Cannot create admin_users');
22+
}
23+
24+
$this->dbforge->add_field(array(
25+
'credential_hash' => array('type' => 'CHAR', 'constraint' => 64),
26+
'user_id' => array('type' => 'CHAR', 'constraint' => 64),
27+
'credential_json' => array('type' => 'TEXT'),
28+
'created_at' => array('type' => 'BIGINT'),
29+
'last_used_at' => array('type' => 'BIGINT', 'null' => TRUE),
30+
'revoked_at' => array('type' => 'BIGINT', 'null' => TRUE),
31+
));
32+
$this->dbforge->add_key('credential_hash', TRUE);
33+
$this->dbforge->add_key('user_id');
34+
if (!$this->dbforge->create_table('admin_credentials', TRUE)) {
35+
throw new RuntimeException('Cannot create admin_credentials');
36+
}
37+
38+
$this->dbforge->add_field(array(
39+
'id' => array('type' => 'CHAR', 'constraint' => 64),
40+
'user_id' => array('type' => 'CHAR', 'constraint' => 64, 'null' => TRUE),
41+
'event' => array('type' => 'VARCHAR', 'constraint' => 64),
42+
'occurred_at' => array('type' => 'BIGINT'),
43+
));
44+
$this->dbforge->add_key('id', TRUE);
45+
$this->dbforge->add_key('occurred_at');
46+
if (!$this->dbforge->create_table('admin_audit_log', TRUE)) {
47+
throw new RuntimeException('Cannot create admin_audit_log');
48+
}
49+
}
50+
51+
public function down()
52+
{
53+
// Never silently erase administrator credentials or audit history.
54+
throw new RuntimeException('Automatic destructive rollback is disabled; use an approved recovery procedure.');
55+
}
56+
}

‎tests/admin-schema-smoke.php‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
// Isolated migration contract test: no live database or credentials.
3+
define('BASEPATH', __DIR__);
4+
class CI_Migration
5+
{
6+
public $load;
7+
public $dbforge;
8+
}
9+
class TestForge
10+
{
11+
public array $tables = [];
12+
private array $fields = [];
13+
private array $keys = [];
14+
public function add_field(array $fields): void { $this->fields = $fields; }
15+
public function add_key(string $field, bool $primary = false): void { $this->keys[$field] = $primary; }
16+
public function create_table(string $name, bool $ifNotExists): bool
17+
{
18+
if (!isset($this->tables[$name])) {
19+
$this->tables[$name] = ['fields' => $this->fields, 'keys' => $this->keys];
20+
}
21+
$this->fields = [];
22+
$this->keys = [];
23+
return true;
24+
}
25+
}
26+
class TestLoader
27+
{
28+
public function dbforge(): void {}
29+
}
30+
require __DIR__.'/../htdocs/application/migrations/20261129000001_admin_credentials.php';
31+
$migration = new Migration_Admin_credentials();
32+
$migration->load = new TestLoader();
33+
$migration->dbforge = new TestForge();
34+
$migration->up();
35+
$tables = $migration->dbforge->tables;
36+
function check(bool $condition, string $message): void
37+
{
38+
if (!$condition) {
39+
throw new RuntimeException($message);
40+
}
41+
}
42+
check(array_keys($tables) === ['admin_users', 'admin_credentials', 'admin_audit_log'], 'Unexpected schema scope');
43+
check($tables['admin_users']['fields']['enabled']['default'] === 0, 'Accounts must default disabled');
44+
check($tables['admin_credentials']['keys']['credential_hash'] === true, 'Credential hash must be unique');
45+
check(isset($tables['admin_credentials']['fields']['revoked_at']), 'Missing revocation field');
46+
$migration->up();
47+
check($tables === $migration->dbforge->tables, 'Repeat migration changed schema definition');
48+
$blocked = false;
49+
try { $migration->down(); } catch (RuntimeException $exception) { $blocked = true; }
50+
check($blocked, 'Destructive rollback was not blocked');
51+
echo "PASS: additive schema contract (mock DBForge; real database not exercised)\n";

0 commit comments

Comments
 (0)