You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					50 lines
				
				1.5 KiB
			
		
		
			
		
	
	
					50 lines
				
				1.5 KiB
			| 
								 
											12 years ago
										 
									 | 
							
								<?php
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
								namespace yiiunit\extensions\authclient\signature;
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								use yiiunit\extensions\authclient\TestCase;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								class BaseMethodTest extends TestCase
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
									/**
							 | 
						||
| 
								 | 
							
									 * Creates test signature method instance.
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
									 * @return \yii\authclient\signature\BaseMethod
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
									 */
							 | 
						||
| 
								 | 
							
									protected function createTestSignatureMethod()
							 | 
						||
| 
								 | 
							
									{
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
										$signatureMethod = $this->getMock('\yii\authclient\signature\BaseMethod', ['getName', 'generateSignature']);
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
										$signatureMethod->expects($this->any())->method('getName')->will($this->returnValue('testMethodName'));
							 | 
						||
| 
								 | 
							
										$signatureMethod->expects($this->any())->method('generateSignature')->will($this->returnValue('testSignature'));
							 | 
						||
| 
								 | 
							
										return $signatureMethod;
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									// Tests :
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									public function testGenerateSignature()
							 | 
						||
| 
								 | 
							
									{
							 | 
						||
| 
								 | 
							
										$signatureMethod = $this->createTestSignatureMethod();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										$baseString = 'test_base_string';
							 | 
						||
| 
								 | 
							
										$key = 'test_key';
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										$signature = $signatureMethod->generateSignature($baseString, $key);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										$this->assertNotEmpty($signature, 'Unable to generate signature!');
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									/**
							 | 
						||
| 
								 | 
							
									 * @depends testGenerateSignature
							 | 
						||
| 
								 | 
							
									 */
							 | 
						||
| 
								 | 
							
									public function testVerify()
							 | 
						||
| 
								 | 
							
									{
							 | 
						||
| 
								 | 
							
										$signatureMethod = $this->createTestSignatureMethod();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										$baseString = 'test_base_string';
							 | 
						||
| 
								 | 
							
										$key = 'test_key';
							 | 
						||
| 
								 | 
							
										$signature = 'unsigned';
							 | 
						||
| 
								 | 
							
										$this->assertFalse($signatureMethod->verify($signature, $baseString, $key), 'Unsigned signature is valid!');
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										$generatedSignature = $signatureMethod->generateSignature($baseString, $key);
							 | 
						||
| 
								 | 
							
										$this->assertTrue($signatureMethod->verify($generatedSignature, $baseString, $key), 'Generated signature is invalid!');
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								}
							 |