Skip to content

Commit 1788601

Browse files
authored
Merge pull request #24 from tattersoftware/session-length
Session ID Length
2 parents b90f6d5 + c5006d5 commit 1788601

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Tatter\Visits\Database\Migrations;
4+
5+
use CodeIgniter\Database\Migration;
6+
7+
class AlterSessionLength extends Migration
8+
{
9+
/**
10+
* @return void
11+
*/
12+
public function up()
13+
{
14+
$this->forge->modifyColumn('visits', [
15+
'session_id' => ['type' => 'varchar', 'constraint' => 127],
16+
]);
17+
}
18+
19+
/**
20+
* @return void
21+
*/
22+
public function down()
23+
{
24+
$this->forge->modifyColumn('visits', [
25+
'session_id' => ['type' => 'varchar', 'constraint' => 32],
26+
]);
27+
}
28+
}

src/Models/VisitModel.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ class VisitModel extends Model
3030
'fragment',
3131
];
3232
protected $validationRules = [
33-
'host' => 'required',
34-
'path' => 'required',
33+
'host' => 'required',
34+
'path' => 'required',
35+
'session_id' => 'permit_empty|max_length[127]',
3536
];
3637

3738
/**

tests/ModelTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,18 @@ public function testMakeFromRequestConvertsIp(): void
129129

130130
unset($_SERVER['REMOTE_ADDR']);
131131
}
132+
133+
/**
134+
* @see https://github.com/tattersoftware/codeigniter4-visits/issues/23
135+
*/
136+
public function testAllowsLongSessionIds(): void
137+
{
138+
$expected = 'Who shall call them from the grey twilight the forgotten people The heir of him to whom the oath they swore';
139+
fake(VisitModel::class, ['session_id' => $expected]);
140+
141+
$result = $this->model->first();
142+
143+
$this->assertInstanceOf(Visit::class, $result);
144+
$this->assertSame($expected, $result->session_id);
145+
}
132146
}

0 commit comments

Comments
 (0)