Skip to content

Commit

Permalink
Merge pull request #24 from tattersoftware/session-length
Browse files Browse the repository at this point in the history
Session ID Length
  • Loading branch information
MGatner authored Jul 12, 2022
2 parents b90f6d5 + c5006d5 commit 1788601
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
28 changes: 28 additions & 0 deletions src/Database/Migrations/20220712095055_alter_session_length.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Tatter\Visits\Database\Migrations;

use CodeIgniter\Database\Migration;

class AlterSessionLength extends Migration
{
/**
* @return void
*/
public function up()
{
$this->forge->modifyColumn('visits', [
'session_id' => ['type' => 'varchar', 'constraint' => 127],
]);
}

/**
* @return void
*/
public function down()
{
$this->forge->modifyColumn('visits', [
'session_id' => ['type' => 'varchar', 'constraint' => 32],
]);
}
}
5 changes: 3 additions & 2 deletions src/Models/VisitModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ class VisitModel extends Model
'fragment',
];
protected $validationRules = [
'host' => 'required',
'path' => 'required',
'host' => 'required',
'path' => 'required',
'session_id' => 'permit_empty|max_length[127]',
];

/**
Expand Down
14 changes: 14 additions & 0 deletions tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,18 @@ public function testMakeFromRequestConvertsIp(): void

unset($_SERVER['REMOTE_ADDR']);
}

/**
* @see https://github.com/tattersoftware/codeigniter4-visits/issues/23
*/
public function testAllowsLongSessionIds(): void
{
$expected = 'Who shall call them from the grey twilight the forgotten people The heir of him to whom the oath they swore';
fake(VisitModel::class, ['session_id' => $expected]);

$result = $this->model->first();

$this->assertInstanceOf(Visit::class, $result);
$this->assertSame($expected, $result->session_id);
}
}

0 comments on commit 1788601

Please sign in to comment.