Skip to content

Commit 7445a64

Browse files
committed
merge qiniu
2 parents 0b62fc1 + 53bfd3a commit 7445a64

File tree

7 files changed

+32
-30
lines changed

7 files changed

+32
-30
lines changed

.travis.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ php:
88
- 5.5
99
- 5.6
1010
before_script:
11-
- export QINIU_ACCESS_KEY="QWYn5TFQsLLU1pL5MFEmX3s5DmHdUThav9WyOWOm"
12-
- export QINIU_SECRET_KEY="Bxckh6FA-Fbs9Yt3i3cbKVK22UPBmAOHJcL95pGz"
13-
- export QINIU_BUCKET_NAME="phpsdk"
14-
- export QINIU_KEY_NAME="php-logo.png"
1511
- export QINIU_TEST_ENV="travis"
1612
- travis_retry composer self-update
1713
- travis_retry composer install --no-interaction --prefer-source --dev

src/Qiniu/Auth.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ public function __construct($accessKey, $secretKey)
1414
$this->secretKey = $secretKey;
1515
}
1616

17-
public function token($data)
17+
public function sign($data)
1818
{
1919
$hmac = hash_hmac('sha1', $data, $this->secretKey, true);
2020
return $this->accessKey . ':' . \Qiniu\base64_urlSafeEncode($hmac);
2121
}
2222

23-
public function tokenWithData($data)
23+
public function signWithData($data)
2424
{
2525
$data = \Qiniu\base64_urlSafeEncode($data);
26-
return $this->token($data) . ':' . $data;
26+
return $this->sign($data) . ':' . $data;
2727
}
2828

29-
public function tokenOfRequest($urlString, $body, $contentType = null)
29+
public function signRequest($urlString, $body, $contentType = null)
3030
{
3131
$url = parse_url($urlString);
3232
$data = '';
@@ -42,12 +42,12 @@ public function tokenOfRequest($urlString, $body, $contentType = null)
4242
($contentType == 'application/x-www-form-urlencoded') || $contentType == 'application/json') {
4343
$data .= $body;
4444
}
45-
return $this->token($data);
45+
return $this->sign($data);
4646
}
4747

4848
public function verifyCallback($contentType, $originAuthorization, $url, $body)
4949
{
50-
$authorization = 'QBox ' . $this->tokenOfRequest($url, $body, $contentType);
50+
$authorization = 'QBox ' . $this->signRequest($url, $body, $contentType);
5151
return $originAuthorization === $authorization;
5252
}
5353

@@ -63,7 +63,7 @@ public function privateDownloadUrl($baseUrl, $expires = 3600)
6363
}
6464
$baseUrl .= $deadline;
6565

66-
$token = $this->token($baseUrl);
66+
$token = $this->sign($baseUrl);
6767
return "$baseUrl&token=$token";
6868
}
6969

@@ -79,10 +79,12 @@ public function uploadToken(
7979
if ($key != null) {
8080
$scope .= ':' . $key;
8181
}
82-
$args = array('scope' => $scope, 'deadline' => $deadline);
83-
self::copyPolicy($args, $policy, $strictPolicy);
82+
$args = array();
83+
$args = self::copyPolicy($args, $policy, $strictPolicy);
84+
$args['scope'] = $scope;
85+
$args['deadline'] = $deadline;
8486
$b = json_encode($args);
85-
return $this->tokenWithData($b);
87+
return $this->signWithData($b);
8688
}
8789

8890
/**
@@ -129,11 +131,12 @@ private static function copyPolicy($policy, $originPolicy, $strictPolicy)
129131
$policy[$key] = $value;
130132
}
131133
}
134+
return $policy;
132135
}
133136

134137
public function authorization($url, $body = null, $contentType = null)
135138
{
136-
$authorization = 'QBox ' . $this->tokenOfRequest($url, $body, $contentType);
139+
$authorization = 'QBox ' . $this->signRequest($url, $body, $contentType);
137140
return array('Authorization' => $authorization);
138141
}
139142
}

src/Qiniu/Http/Response.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ public function needRetry()
169169

170170
private static function isJson($headers)
171171
{
172-
return isset($headers['Content-Type']) && $headers['Content-Type'] == 'application/json';
172+
return isset($headers['Content-Type']) &&
173+
strpos($headers['Content-Type'], 'application/json') === 0;
173174
}
174175
}

src/Qiniu/Storage/ResumeUploader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ private function post($url, $data)
143143
private function blockSize($uploaded)
144144
{
145145
if ($this->size < $uploaded + Config::BLOCK_SIZE) {
146-
return $bsize = $this->size - $uploaded;
146+
return $this->size - $uploaded;
147147
}
148148
return Config::BLOCK_SIZE;
149149
}

tests/Qiniu/Tests/AuthTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,27 @@ function time()
2222
class AuthTest extends \PHPUnit_Framework_TestCase
2323
{
2424

25-
public function testToken()
25+
public function testSign()
2626
{
2727
global $dummyAuth;
28-
$token = $dummyAuth->token('test');
28+
$token = $dummyAuth->sign('test');
2929
$this->assertEquals('abcdefghklmnopq:mSNBTR7uS2crJsyFr2Amwv1LaYg=', $token);
3030
}
3131

32-
public function testTokenWithData()
32+
public function testSignWithData()
3333
{
3434
global $dummyAuth;
35-
$token = $dummyAuth->tokenWithData('test');
35+
$token = $dummyAuth->signWithData('test');
3636
$this->assertEquals('abcdefghklmnopq:-jP8eEV9v48MkYiBGs81aDxl60E=:dGVzdA==', $token);
3737
}
3838

39-
public function testTokenOfRequest()
39+
public function testSignRequest()
4040
{
4141
global $dummyAuth;
42-
$token = $dummyAuth->tokenOfRequest('http://www.qiniu.com?go=1', 'test', '');
42+
$token = $dummyAuth->signRequest('http://www.qiniu.com?go=1', 'test', '');
4343
$this->assertEquals('abcdefghklmnopq:cFyRVoWrE3IugPIMP5YJFTO-O-Y=', $token);
4444
$ctype = 'application/x-www-form-urlencoded';
45-
$token = $dummyAuth->tokenOfRequest('http://www.qiniu.com?go=1', 'test', $ctype);
45+
$token = $dummyAuth->signRequest('http://www.qiniu.com?go=1', 'test', $ctype);
4646
$this->assertEquals($token, 'abcdefghklmnopq:svWRNcacOE-YMsc70nuIYdaa1e4=');
4747
}
4848

@@ -71,7 +71,9 @@ public function testUploadToken()
7171
global $dummyAuth;
7272
$_SERVER['override_qiniu_auth_time'] = true;
7373
$token = $dummyAuth->uploadToken('1', '2', 3600, array('endUser'=> 'y'));
74-
$exp = 'abcdefghklmnopq:x53hx7845_pygLochtRWlnrL-90=:eyJzY29wZSI6IjE6MiIsImRlYWRsaW5lIjoxMjM0NTcxNDkwfQ==';
74+
// @codingStandardsIgnoreStart
75+
$exp = 'abcdefghklmnopq:yyeexeUkPOROoTGvwBjJ0F0VLEo=:eyJlbmRVc2VyIjoieSIsInNjb3BlIjoiMToyIiwiZGVhZGxpbmUiOjEyMzQ1NzE0OTB9';
76+
// @codingStandardsIgnoreEnd
7577
$this->assertEquals($exp, $token);
7678
unset($_SERVER['override_qiniu_auth_time']);
7779
}

tests/Qiniu/Tests/HttpTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function testGet()
1616
public function testGetQiniu()
1717
{
1818
$response = Client::get('up.qiniu.com');
19-
$this->assertEquals($response->statusCode, 405);
19+
$this->assertEquals(405, $response->statusCode);
2020
$this->assertNotNull($response->body);
2121
$this->assertNotNull($response->xReqId());
2222
$this->assertNotNull($response->xLog());

tests/bootstrap.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
use Qiniu\Auth;
66

7-
$accessKey = getenv('QINIU_ACCESS_KEY');
8-
$secretKey = getenv('QINIU_SECRET_KEY');
7+
$accessKey = 'QWYn5TFQsLLU1pL5MFEmX3s5DmHdUThav9WyOWOm';
8+
$secretKey = 'Bxckh6FA-Fbs9Yt3i3cbKVK22UPBmAOHJcL95pGz';
99
$testAuth = new Auth($accessKey, $secretKey);
10-
$bucketName = getenv('QINIU_BUCKET_NAME');
11-
$key = getenv('QINIU_KEY_NAME');
10+
$bucketName = 'phpsdk';
11+
$key = 'php-logo.png';
1212

1313
$dummyAccessKey = 'abcdefghklmnopq';
1414
$dummySecretKey = '1234567890';

0 commit comments

Comments
 (0)