nexmo 4.8.0 → 5.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,53 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'nexmo'
3
-
4
- describe 'Nexmo::JWT' do
5
- describe 'auth_token method' do
6
- it 'returns the payload encoded with the private key' do
7
- time = Time.now.to_i
8
-
9
- payload = {
10
- 'application_id' => application_id,
11
- 'iat' => time,
12
- 'exp' => time + 3600,
13
- 'jti' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
14
- }
15
-
16
- encoded_token = Nexmo::JWT.auth_token(payload, private_key)
17
-
18
- decode(encoded_token).must_equal(payload)
19
- end
20
-
21
- it 'sets a default value for the iat parameter' do
22
- encoded_token = Nexmo::JWT.auth_token({}, private_key)
23
-
24
- decode(encoded_token).fetch('iat').must_be_kind_of(Integer)
25
- end
26
-
27
- it 'sets a default value for the exp parameter' do
28
- encoded_token = Nexmo::JWT.auth_token({}, private_key)
29
-
30
- decode(encoded_token).fetch('exp').must_be_kind_of(Integer)
31
- end
32
-
33
- it 'sets a default value for the jti parameter' do
34
- encoded_token = Nexmo::JWT.auth_token({}, private_key)
35
-
36
- decode(encoded_token).fetch('jti').must_match(/\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/)
37
- end
38
- end
39
-
40
- private
41
-
42
- def decode(encoded_token)
43
- JWT.decode(encoded_token, private_key, verify=true, {algorithm: 'RS256'}).first
44
- end
45
-
46
- def application_id
47
- @application_id ||= SecureRandom.uuid
48
- end
49
-
50
- def private_key
51
- @private_key ||= OpenSSL::PKey::RSA.new(1024)
52
- end
53
- end
@@ -1,18 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'nexmo'
3
-
4
- describe 'Nexmo::Params' do
5
- describe 'encode method' do
6
- it 'returns a url encoded string containing the given params' do
7
- params = {'name' => 'Example App', 'type' => 'voice'}
8
-
9
- Nexmo::Params.encode(params).must_equal('name=Example+App&type=voice')
10
- end
11
-
12
- it 'flattens array values into multiple key value pairs' do
13
- params = {'ids' => %w[00A0B0C0 00A0B0C1 00A0B0C2]}
14
-
15
- Nexmo::Params.encode(params).must_equal('ids=00A0B0C0&ids=00A0B0C1&ids=00A0B0C2')
16
- end
17
- end
18
- end
@@ -1,20 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'nexmo'
3
-
4
- describe 'Nexmo::Signature' do
5
- let(:secret) { 'secret' }
6
-
7
- describe 'check method' do
8
- it 'returns true if the given params has the correct sig value' do
9
- params = {'a' => '1', 'b' => '2', 'timestamp' => '1461605396', 'sig' => '6af838ef94998832dbfc29020b564830'}
10
-
11
- Nexmo::Signature.check(params, secret).must_equal(true)
12
- end
13
-
14
- it 'returns false otherwise' do
15
- params = {'a' => '1', 'b' => '2', 'timestamp' => '1461605396', 'sig' => 'xxx'}
16
-
17
- Nexmo::Signature.check(params, secret).must_equal(false)
18
- end
19
- end
20
- end