Skip to content

Commit 999e674

Browse files
committed
Tests
1 parent 512ba79 commit 999e674

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

tests/config.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
session_start();
4+
require dirname(__DIR__) . '/src/csrf.php';
5+
6+
// Konfigüre ediyoruz
7+
$csrf = new Csrf([
8+
'key' => 'SuperKey',
9+
'secret' => 'SuperSecret'
10+
]);
11+
12+
?>

tests/post.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
require dirname(__DIR__) . '/tests/config.php';
4+
5+
if($_POST){
6+
7+
$firstname = $_POST['firstname'];
8+
$_csrf = $_POST['_csrf'];
9+
10+
if($csrf->Check($_csrf)){
11+
12+
$result = "Token is correct";
13+
$csrf->Reset();
14+
15+
}else{
16+
17+
$result = "Token is not correct";
18+
$csrf->Reset();
19+
20+
}
21+
22+
}
23+
24+
?>
25+
<b>Form Data:</b><br>
26+
<pre>
27+
<?php @print_r($_POST); ?>
28+
</pre><br>
29+
<b>Session Data:</b><br>
30+
<pre>
31+
<?php print_r($_SESSION); ?>
32+
</pre><br>
33+
<b>Token Verification Result:</b> <?= $result; ?>

tests/test.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php require dirname(__DIR__) . '/tests/config.php'; ?>
2+
<form method="POST" action="post.php">
3+
<b>Firstname:</b><br>
4+
<input type="text" name="firstname"><br>
5+
<b>_CSRF Token:</b><br>
6+
<input type="text" name="_csrf" value="<?= $csrf->Get(); ?>"><br>
7+
<button type="submit">Submit</button>
8+
</form>

0 commit comments

Comments
 (0)