How to use testKey method of token class

Best Atoum code snippet using token.testKey

TokenAuthTest.php

Source:TokenAuthTest.php Github

copy

Full Screen

...21namespace Matricali\Security\EdgeAuth\Test;22use Matricali\Security\EdgeAuth\TokenAuth;23class TokenAuthTest extends \PHPUnit_Framework_TestCase24{25 protected $testKey = 'a1b2c3d4e5f6';26 public function testGeneration()27 {28 $generator = new TokenAuth($this->testKey);29 $token = $generator->generateToken();30 $this->assertNotEmpty($token);31 }32 /**33 * @expectedException \Matricali\Security\EdgeAuth\InvalidArgumentException34 */35 public function testInvalidAlgorithm()36 {37 $auth = new TokenAuth($this->testKey);38 $auth->setAlgorithm('inVaLid');39 }40 public function testValidIPv4()41 {42 $auth = new TokenAuth($this->testKey);43 $this->assertEquals('', $auth->getIp());44 $this->assertEquals('', $auth->getIpField());45 // Valid IPv446 $auth->setIp('127.0.0.1');47 $this->assertEquals('127.0.0.1', $auth->getIp());48 $this->assertEquals('ip=127.0.0.1'.$auth->getFieldDelimiter(), $auth->getIpField());49 }50 /**51 * @expectedException \Matricali\Security\EdgeAuth\InvalidArgumentException52 */53 public function testInvalidIPv4()54 {55 $auth = new TokenAuth($this->testKey);56 $auth->setIp('127.0.0.300');57 }58 public function testValidIPv6()59 {60 $auth = new TokenAuth($this->testKey);61 $this->assertEquals('', $auth->getIp());62 $this->assertEquals('', $auth->getIpField());63 // Valid IPv464 $auth->setIp('2001:0db8:85a3:08d3:1319:8a2e:0370:7334');65 $this->assertEquals('2001:0db8:85a3:08d3:1319:8a2e:0370:7334', $auth->getIp());66 $this->assertEquals('ip=2001:0db8:85a3:08d3:1319:8a2e:0370:7334'.$auth->getFieldDelimiter(), $auth->getIpField());67 }68 /**69 * @expectedException \Matricali\Security\EdgeAuth\InvalidArgumentException70 */71 public function testInvalidIPv6()72 {73 $auth = new TokenAuth($this->testKey);74 $auth->setIp('2001:0db8:85a3:08d3:xxxx:8a2e:0370:7334');75 }76 public function testStartTime()77 {78 $auth = new TokenAuth($this->testKey);79 $gstv = new \ReflectionMethod('Matricali\Security\EdgeAuth\TokenAuth', 'getStartTimeValue');80 $gstv->setAccessible(true);81 $this->assertEquals(0, $auth->getStartTime());82 $this->assertEquals(time(), $gstv->invoke($auth));83 $this->assertEquals('', $auth->getStartTimeField());84 $auth->setStartTime('now');85 $this->assertEquals(time(), $auth->getStartTime());86 $this->assertEquals(time(), $gstv->invoke($auth));87 $this->assertEquals('st='.time().$auth->getFieldDelimiter(), $auth->getStartTimeField());88 $auth->setStartTime(12345);89 $this->assertEquals(12345, $auth->getStartTime());90 $this->assertEquals(12345, $gstv->invoke($auth));91 $this->assertEquals('st='. 12345 .$auth->getFieldDelimiter(), $auth->getStartTimeField());92 $auth = new TokenAuth($this->testKey);93 try {94 $auth->setStartTime('');95 } catch (\Exception $e1) {96 }97 $this->assertInstanceOf('Matricali\Security\EdgeAuth\InvalidArgumentException', $e1);98 $this->assertEquals(0, $auth->getStartTime());99 $this->assertEquals(time(), $gstv->invoke($auth));100 $this->assertEquals('', $auth->getStartTimeField());101 }102 public function testWindow()103 {104 $auth = new TokenAuth($this->testKey);105 // Default window time106 $this->assertEquals(300, $auth->getWindow());107 $auth->setWindow(500);108 $this->assertEquals(500, $auth->getWindow());109 $auth = new TokenAuth($this->testKey);110 try {111 $auth->setWindow('abc');112 } catch (\Exception $e1) {113 }114 $this->assertInstanceOf('Matricali\Security\EdgeAuth\InvalidArgumentException', $e1);115 $this->assertEquals(300, $auth->getWindow());116 try {117 $auth->setWindow(0);118 } catch (\Exception $e2) {119 }120 $this->assertInstanceOf('Matricali\Security\EdgeAuth\InvalidArgumentException', $e2);121 $this->assertEquals(300, $auth->getWindow());122 }123 public function testAcl()124 {125 $auth = new TokenAuth($this->testKey);126 $this->assertEquals('', $auth->getAcl());127 $this->assertEquals('acl=/*'.$auth->getFieldDelimiter(), $auth->getAclField());128 $auth->setAcl('test');129 $this->assertEquals('test', $auth->getAcl());130 $this->assertEquals('acl=test'.$auth->getFieldDelimiter(), $auth->getAclField());131 $auth = new TokenAuth($this->testKey);132 $auth->setUrl('https://example.com/protected/resource');133 $this->assertEquals('', $auth->getAclField()); // If we have an URL we shouldn't have an ACL134 try {135 $auth->setAcl('test');136 } catch (\Exception $e1) {137 }138 $this->assertInstanceOf('Matricali\Security\EdgeAuth\InvalidArgumentException', $e1);139 }140 public function testUrl()141 {142 $auth = new TokenAuth($this->testKey);143 $this->assertEquals('', $auth->getUrl());144 $this->assertEquals('', $auth->getUrlField());145 $auth->setUrl('https://example.com/protected/resource');146 $this->assertEquals('https://example.com/protected/resource', $auth->getUrl());147 $this->assertEquals('url=https://example.com/protected/resource'.$auth->getFieldDelimiter(), $auth->getUrlField());148 $auth = new TokenAuth($this->testKey);149 $auth->setAcl('test');150 $this->assertEquals('', $auth->getUrlField()); // If we have an URL we shouldn't have an ACL151 try {152 $auth->setUrl('https://example.com/');153 } catch (\Exception $e1) {154 }155 $this->assertInstanceOf('Matricali\Security\EdgeAuth\InvalidArgumentException', $e1);156 }157 public function testSession()158 {159 $auth = new TokenAuth($this->testKey);160 $this->assertEquals('', $auth->getSessionId());161 $this->assertEquals('', $auth->getSessionIdField());162 $auth->setSessionId('e10adc3949ba59abbe56e057f20f883e');163 $this->assertEquals('e10adc3949ba59abbe56e057f20f883e', $auth->getSessionId());164 $this->assertEquals('id=e10adc3949ba59abbe56e057f20f883e'.$auth->getFieldDelimiter(), $auth->getSessionIdField());165 $auth->setSessionId(123456778);166 $this->assertEquals('123456778', $auth->getSessionId());167 $this->assertEquals('id=123456778'.$auth->getFieldDelimiter(), $auth->getSessionIdField());168 $auth = new TokenAuth($this->testKey);169 try {170 $auth->setSessionId([]);171 } catch (\Exception $e1) {172 }173 $this->assertInstanceOf('Matricali\Security\EdgeAuth\InvalidArgumentException', $e1);174 $this->assertEquals('', $auth->getSessionId());175 $this->assertEquals('', $auth->getSessionIdField());176 try {177 $auth->setSessionId(new \StdClass());178 } catch (\Exception $e2) {179 }180 $this->assertInstanceOf('Matricali\Security\EdgeAuth\InvalidArgumentException', $e2);181 $this->assertEquals('', $auth->getSessionId());182 $this->assertEquals('', $auth->getSessionIdField());183 }184 public function testData()185 {186 $auth = new TokenAuth($this->testKey);187 $this->assertEquals('', $auth->getData());188 $this->assertEquals('', $auth->getDataField());189 $auth->setData('e10adc3949ba59abbe56e057f20f883e');190 $this->assertEquals('e10adc3949ba59abbe56e057f20f883e', $auth->getData());191 $this->assertEquals('data=e10adc3949ba59abbe56e057f20f883e'.$auth->getFieldDelimiter(), $auth->getDataField());192 $auth->setData(123456778);193 $this->assertEquals('123456778', $auth->getData());194 $this->assertEquals('data=123456778'.$auth->getFieldDelimiter(), $auth->getDataField());195 $auth = new TokenAuth($this->testKey);196 try {197 $auth->setData([]);198 } catch (\Exception $e1) {199 }200 $this->assertInstanceOf('Matricali\Security\EdgeAuth\InvalidArgumentException', $e1);201 $this->assertEquals('', $auth->getData());202 $this->assertEquals('', $auth->getDataField());203 try {204 $auth->setData(new \StdClass());205 } catch (\Exception $e2) {206 }207 $this->assertInstanceOf('Matricali\Security\EdgeAuth\InvalidArgumentException', $e2);208 $this->assertEquals('', $auth->getData());209 $this->assertEquals('', $auth->getDataField());210 }211 public function testSalt()212 {213 $auth = new TokenAuth($this->testKey);214 $this->assertEquals('', $auth->getSalt());215 $this->assertEquals('', $auth->getSaltField());216 $auth->setSalt('s4lt');217 $this->assertEquals('s4lt', $auth->getSalt());218 $this->assertEquals('salt=s4lt'.$auth->getFieldDelimiter(), $auth->getSaltField());219 $auth->setSalt(123456778);220 $this->assertEquals('123456778', $auth->getSalt());221 $this->assertEquals('salt=123456778'.$auth->getFieldDelimiter(), $auth->getSaltField());222 $auth = new TokenAuth($this->testKey);223 try {224 $auth->setSalt([]);225 } catch (\Exception $e1) {226 }227 $this->assertInstanceOf('Matricali\Security\EdgeAuth\InvalidArgumentException', $e1);228 $this->assertEquals('', $auth->getSalt());229 $this->assertEquals('', $auth->getSaltField());230 try {231 $auth->setSalt(new \StdClass());232 } catch (\Exception $e2) {233 }234 $this->assertInstanceOf('Matricali\Security\EdgeAuth\InvalidArgumentException', $e2);235 $this->assertEquals('', $auth->getSalt());236 $this->assertEquals('', $auth->getSaltField());237 }238 public function testKey()239 {240 $auth = new TokenAuth($this->testKey);241 $this->assertEquals($this->testKey, $auth->getKey());242 $auth->setKey('abcd1234');243 $this->assertEquals('abcd1234', $auth->getKey());244 $auth = new TokenAuth($this->testKey);245 try {246 $auth->setKey('zxvft');247 } catch (\Exception $e1) {248 }249 $this->assertInstanceOf('Matricali\Security\EdgeAuth\InvalidArgumentException', $e1);250 $this->assertEquals($this->testKey, $auth->getKey());251 try {252 $auth->setKey('abcd1234f'); // Must be an even number of characters253 } catch (\Exception $e2) {254 }255 $this->assertInstanceOf('Matricali\Security\EdgeAuth\InvalidArgumentException', $e2);256 $this->assertEquals($this->testKey, $auth->getKey());257 }258 public function testFieldDelimiter()259 {260 $auth = new TokenAuth($this->testKey);261 $this->assertEquals('~', $auth->getFieldDelimiter());262 $auth->setFieldDelimiter('|');263 $this->assertEquals('|', $auth->getFieldDelimiter());264 }265 public function testEarlyUrlEncoding()266 {267 $encode = new \ReflectionMethod('Matricali\Security\EdgeAuth\TokenAuth', 'encode');268 $encode->setAccessible(true);269 $auth = new TokenAuth($this->testKey);270 $this->assertFalse($auth->getEarlyUrlEncoding());271 $this->assertEquals('test ', $encode->invoke($auth, 'test '));272 $auth->setEarlyUrlEncoding(true);273 $this->assertTrue($auth->getEarlyUrlEncoding());274 $this->assertEquals('test%20', $encode->invoke($auth, 'test '));275 }276 public function testSha256()277 {278 $auth = new TokenAuth($this->testKey);279 $auth->setAlgorithm(TokenAuth::ALGORITHM_SHA256);280 $token = $auth->generateToken();281 $this->assertNotEmpty($token);282 }283 public function testSha1()284 {285 $auth = new TokenAuth($this->testKey);286 $auth->setAlgorithm(TokenAuth::ALGORITHM_SHA1);287 $token = $auth->generateToken();288 $this->assertNotEmpty($token);289 }290 public function testMd5()291 {292 $auth = new TokenAuth($this->testKey);293 $auth->setAlgorithm(TokenAuth::ALGORITHM_MD5);294 $token = $auth->generateToken();295 $this->assertNotEmpty($token);296 }297}...

Full Screen

Full Screen

userConn.php

Source:userConn.php Github

copy

Full Screen

...13//new PDOconnect();14include $_SERVER["DOCUMENT_ROOT"].$xppUrl ."/src/database/config/db.php";15// throwError($msg)16// removeUsersCookie()17// checkToken($token, $nick, $testKey, $userKey, $testID)18include $_SERVER["DOCUMENT_ROOT"].$xppUrl ."/src/database/userService/userValidation.php";19//IF USE POST20$nick = $_COOKIE["nick"] ?? $_POST["nick"] ?? false;21//if user use nick22$useNick = $_POST["useNick"] ?? false;23$fName = $_POST["fName"] ?? false;24$lName = $_POST["lName"] ?? false;25$testKey = $_COOKIE["testKey"] ?? $_POST["testKey"] ?? false;26//these data are gated after join to test27$checkTokenVar = $_POST["checkToken"] ?? false;28$token = $_COOKIE["token"] ?? $_POST["token"] ?? false;29$userKey = $_COOKIE["userKey"] ?? $_POST["userKey"] ?? false;30$testID = $_COOKIE["testID"] ?? $_POST["testID"] ?? false;31$db = new PDOconnect();32$WBconf = new WebSiteConf();33function checkKey($testKey) {34 global $db;35 if (!$testKey) return false;36 $sql = "SELECT * FROM tests WHERE t_key = ?";37 $result = $db->run($sql,[$testKey]);38 if (!$result) return false;39 if ($row = $result->fetch(PDO::FETCH_ASSOC)) {40 if ($row["public"] == "0") return false;41 return $row; 42 }43 44 return false;45}46//I know, that this token is not like a normal one, but for the purpose of this project, it will be enough47function getUserEsToken($nick = null, $fName, $lName = NULL, $testKey) {48 global $db;49 date_default_timezone_set($db->getUTF());50 $userKey = genEsKey();51 $tmp_fName = $fName;52 $tmp_lName = $lName;53 // !!!54 //$tmp_fName = mb_substr($tmp_fName, 0, 3);55 //$tmp_lName = mb_substr($tmp_lName, 0, 3);56 $nick = $tmp_fName.$tmp_lName.'#'.substr($userKey, 0, 3);57 $expirationTime = 30;58 $expirationDate = date("Y-m-d H:i:s",mktime(59 date('H'), 60 date('i') + $expirationTime, 61 date('s') + rand(1,59), 62 date('m'), 63 date('d'),64 date('Y')65 ));66 //date("Y-m-d H:i:s");67 $sold = SERV_SOLD;68 $userInfo = $nick.$testKey.$userKey.$sold;69 $h = hash("sha256",$userInfo);70 //$encodedExpDate = mc_encrypt($expirationDate, ENCRYPTION_KEY);71 //pseudo token :)72 //$esToken = $h.".".$encodedExpDate;73 $esToken = $h.".".hash("sha256",$expirationDate);74 return ["token"=>$esToken, "nick"=>$nick, "testKey"=>$testKey, "userKey"=>$userKey, "fName"=>$fName, "lName"=>$lName];75}76function insertIntoDB($userInfo, $testInfo, $tokenToCheck = null) {77 global $db;78 global $WBconf;79 80 if($tokenToCheck) {81 removeUsersCookie();82 throwError("cookieError");83 }84 $sql = "INSERT INTO participants (test_id, nickname, f_name, l_name, token) 85 VALUES (?, ?, ?, ?, ?)86 ";87 $result = $db->run($sql,[88 $testInfo["id"],89 $userInfo["nick"],90 $userInfo["fName"], 91 $userInfo["lName"],92 $userInfo["token"]93 ]);94 95 if (!$result) throwError("insertError");96 $myID = $db->conn->lastInsertId();97 //unset($userInfo["token"]);98 //35 min99 $cookieTime = $WBconf->getQuizCookieTime();100 $pid = $db->domainPrefix."_pid";101 setLocalCookie($pid, $myID, $cookieTime);102 setLocalCookie("token", $userInfo["token"], $cookieTime);103 setLocalCookie("nick", $userInfo["nick"], $cookieTime);104 setLocalCookie("testKey", $userInfo["testKey"], $cookieTime);105 setLocalCookie("userKey", $userInfo["userKey"], $cookieTime);106 setLocalCookie("fName", $userInfo["fName"], $cookieTime);107 setLocalCookie("lName", $userInfo["lName"], $cookieTime);108 setLocalCookie("testID", $testInfo["id"], $cookieTime);109 setLocalCookie("qMax", $testInfo["q_max"], $cookieTime);110 if ($testInfo["session_mode"] == 1) {111 setLocalCookie("waitingMode", 1, $cookieTime);112 }113 exit(json_encode(["access"=>"ok"]));114}115/*116...userVerification.php...117*/118//first we check for correct user names119if (!$checkTokenVar) {120 if ($useNick) {121 if (!$nick) throwError("nameError");122 if (strlen($nick) > 6) throwError("lenError");123 }else {124 if (!$fName || empty($fName)) throwError("fNameError");125 if (!$lName || empty($lName)) throwError("lNameError");126 }127}128//checks for tests key129$testData = null;130if($testsRow = checkKey($testKey)) {131 $testData = $testsRow;132}else {133 throwError("badKey");134}135//checks for token136//if participant have already joined137if ($checkTokenVar){138 $chackedToken = checkToken($db, $token, $nick, $testKey, $userKey, $testID);139 if ($chackedToken == true)140 exit(json_encode(["access"=>"ok"]));141}else {142 if (!$testKey) throwError("badKey");143 $esToken = getUserEsToken(null, $fName, $lName, $testKey);144 insertIntoDB($esToken, $testData, $token);145}146$db->closeConnection();147throwError("noAnswer");148?>...

Full Screen

Full Screen

SessionStorageTest.php

Source:SessionStorageTest.php Github

copy

Full Screen

...41 * @return void42 */43 public function testSessionStorageGetToken(): void44 {45 $testKey = 'test_key';46 $testValue = 'test_value';47 $this->sessionMock->expects($this->once())48 ->method('get')49 ->with(SessionStorage::SESSION_KEY_PREFIX . $testKey)50 ->willReturn($testValue);51 $this->assertSame($testValue, $this->sessionStorage->getToken($testKey));52 }53 /**54 * @return void55 */56 public function testSessionStorageSetToken(): void57 {58 $testKey = 'test_key';59 $testValue = 'test_value';60 $this->sessionMock->expects($this->once())61 ->method('set')62 ->with(SessionStorage::SESSION_KEY_PREFIX . $testKey, $testValue);63 $this->sessionStorage->setToken($testKey, $testValue);64 }65 /**66 * @return void67 */68 public function testSessionStorageDeleteToken(): void69 {70 $testKey = 'test_key';71 $this->sessionMock->expects($this->once())72 ->method('remove')73 ->with(SessionStorage::SESSION_KEY_PREFIX . $testKey);74 $this->sessionStorage->deleteToken($testKey);75 }76}...

Full Screen

Full Screen

testKey

Using AI Code Generation

copy

Full Screen

1$token = new Token();2$token->testKey();3$token = new Token();4$token->testKey();5$token = new Token();6$token->testKey();

Full Screen

Full Screen

testKey

Using AI Code Generation

copy

Full Screen

1$token = new Token();2if($token->testKey($_POST['token'])){3}4$token = new Token();5if($token->testKey($_POST['token'])){6}7$token = new Token();8if($token->testKey($_POST['token'])){9}10$token = new Token();11if($token->testKey($_POST['token'])){12}13$token = new Token();14if($token->testKey($_POST['token'])){15}16$token = new Token();17if($token->testKey($_POST['token'])){18}19$token = new Token();20if($token->testKey($_POST['token'])){21}22$token = new Token();23if($token->testKey($_POST['token'])){24}25$token = new Token();26if($token->testKey($_POST['token'])){27}28$token = new Token();29if($token->testKey($_POST['token'])){30}31$token = new Token();32if($token->testKey($_POST['token'])){33}34$token = new Token();35if($token->testKey($_POST['token'])){36}37$token = new Token();

Full Screen

Full Screen

testKey

Using AI Code Generation

copy

Full Screen

1$token = Token::testKey();2$token = Token::testKey();3$token = Token::testKey();4$token = Token::testKey();5$token = Token::testKey();6$token = Token::testKey();7$token = Token::testKey();8$token = Token::testKey();9$token = Token::testKey();10$token = Token::testKey();

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Atoum automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger testKey code on LambdaTest Cloud Grid

Execute automation tests with testKey on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful