fastly 2.3.1 → 2.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.env.example +3 -0
- data/CHANGELOG.md +21 -0
- data/Gemfile +5 -1
- data/README.md +12 -8
- data/lib/fastly.rb +2 -1
- data/lib/fastly/backend.rb +1 -1
- data/lib/fastly/belongs_to_service_and_version.rb +3 -3
- data/lib/fastly/client.rb +22 -9
- data/lib/fastly/gem_version.rb +1 -1
- data/lib/fastly/service.rb +2 -1
- data/lib/fastly/token.rb +36 -0
- data/test/fastly/client_test.rb +27 -1
- data/test/fastly/token_test.rb +131 -0
- data/test/helper.rb +1 -0
- data/test/token_test.rb +64 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff6374dedf0a4320acb1bb370b700f31dffbb841ad039e717c9b6bd713a6cb5a
|
4
|
+
data.tar.gz: f53667b8fa95b6e9cf013ec23c94feee19b860c28de60aba3fee4ddd17ffaa4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3115a7e69149466f180e3d823c13ef9d4a895178a6e33e02522afa1b5551df59da7655dd3c316eba9cb0be0df2494b2b2f4a6803a2ec6b04cb8f4f1b06be11f
|
7
|
+
data.tar.gz: c7a1a39686da60e1986b24d7ef7d94cdba247e29117a99bed51924e23716da3dc72cc44869e1b711f75745309ff71597c165d2048fb5b43ed38fa6d0d2fc4e88
|
data/.env.example
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,26 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [v2.5.0](https://github.com/fastly/fastly-ruby/tree/v2.5.0) (2020-01-16)
|
4
|
+
[Full Changelog](https://github.com/fastly/fastly-ruby/compare/v2.4.0...v2.5.0)
|
5
|
+
|
6
|
+
**Merged pull requests:**
|
7
|
+
|
8
|
+
- Add tokens.rb [\#150](https://github.com/fastly/fastly-ruby/pull/150) ([malachy-mcconnell](https://github.com/malachy-mcconnell))
|
9
|
+
|
10
|
+
## [v2.4.0](https://github.com/fastly/fastly-ruby/tree/v2.4.0) (2019-07-29)
|
11
|
+
[Full Changelog](https://github.com/fastly/fastly-ruby/compare/v2.3.1...v2.4.0)
|
12
|
+
|
13
|
+
**Merged pull requests:**
|
14
|
+
|
15
|
+
- \[Backend\] Add override\_host attribute for Backend [\#146](https://github.com/fastly/fastly-ruby/pull/146) ([werkshy](https://github.com/werkshy))
|
16
|
+
|
17
|
+
## [v2.3.1](https://github.com/fastly/fastly-ruby/tree/v2.3.1) (2019-07-25)
|
18
|
+
[Full Changelog](https://github.com/fastly/fastly-ruby/compare/v2.3.0...v2.3.1)
|
19
|
+
|
20
|
+
**Merged pull requests:**
|
21
|
+
|
22
|
+
- Correct stats API path [\#147](https://github.com/fastly/fastly-ruby/pull/147) ([thommahoney](https://github.com/thommahoney))
|
23
|
+
|
3
24
|
## [v2.3.0](https://github.com/fastly/fastly-ruby/tree/v2.3.0) (2019-04-26)
|
4
25
|
[Full Changelog](https://github.com/fastly/fastly-ruby/compare/v2.2.0...v2.3.0)
|
5
26
|
|
data/Gemfile
CHANGED
@@ -4,10 +4,14 @@ gemspec
|
|
4
4
|
|
5
5
|
group :development, :test do
|
6
6
|
gem 'appraisal', '~> 2.1'
|
7
|
-
gem 'rake', '
|
7
|
+
gem 'rake', '>= 12.3.3'
|
8
8
|
gem 'rdoc', '~> 4.1.1'
|
9
9
|
gem 'minitest', '~> 5.3.4'
|
10
10
|
gem 'pry'
|
11
11
|
gem 'rubocop', '~> 0.57.2', require: false
|
12
12
|
gem 'webmock'
|
13
13
|
end
|
14
|
+
|
15
|
+
group :test do
|
16
|
+
gem 'dotenv'
|
17
|
+
end
|
data/README.md
CHANGED
@@ -202,19 +202,23 @@ This option should not be used in a production setting as all HTTP headers, requ
|
|
202
202
|
|
203
203
|
### Notes for testing
|
204
204
|
|
205
|
-
The test suite
|
205
|
+
The test suite tests create and delete three services in sequence, so you may want to create an account just for these tests.
|
206
206
|
|
207
|
-
|
208
|
-
* `FASTLY_TEST_PASSWORD` - Your account password
|
209
|
-
* `FASTLY_TEST_API_KEY` - Your API key (found at https://app.fastly.com/#account)
|
207
|
+
To run the test suite:
|
210
208
|
|
211
|
-
|
212
|
-
|
213
|
-
to
|
209
|
+
1. Generate a personal token for these tests: https://manage.fastly.com/account/personal/tokens
|
210
|
+
|
211
|
+
2. Copy `.env.example` to `.env` and add the values for the variables:
|
212
|
+
|
213
|
+
* `FASTLY_TEST_USER` - Your user email
|
214
|
+
* `FASTLY_TEST_PASSWORD` - Your account password
|
215
|
+
* `FASTLY_TEST_API_KEY` - Your personal token
|
216
|
+
|
217
|
+
3. Run the tests via `bundle exec rake test:unit`
|
214
218
|
|
215
219
|
## Copyright
|
216
220
|
|
217
|
-
Copyright 2011-
|
221
|
+
Copyright 2011-2020 - Fastly, Inc.
|
218
222
|
|
219
223
|
## Redistribution
|
220
224
|
|
data/lib/fastly.rb
CHANGED
@@ -34,6 +34,7 @@ require 'fastly/snippet'
|
|
34
34
|
require 'fastly/dynamic_snippet'
|
35
35
|
require 'fastly/sumologic_logging'
|
36
36
|
require 'fastly/syslog'
|
37
|
+
require 'fastly/token'
|
37
38
|
require 'fastly/s3_logging'
|
38
39
|
require 'fastly/gcs_logging'
|
39
40
|
require 'fastly/user'
|
@@ -151,7 +152,7 @@ class Fastly
|
|
151
152
|
client.get_stats('/stats/regions')
|
152
153
|
end
|
153
154
|
|
154
|
-
[ACL, ACLEntry, User, Customer, Backend, CacheSetting, Condition, Dictionary, DictionaryItem, Director, Domain, Header, Healthcheck, Gzip, Match, PapertrailLogging, RequestSetting, ResponseObject, Service, Snippet, S3Logging, Syslog, VCL, Version].each do |klass|
|
155
|
+
[ACL, ACLEntry, User, Customer, Backend, CacheSetting, Condition, Dictionary, DictionaryItem, Director, Domain, Header, Healthcheck, Gzip, Match, PapertrailLogging, RequestSetting, ResponseObject, Service, Snippet, S3Logging, Syslog, Token, VCL, Version].each do |klass|
|
155
156
|
type = Util.class_to_path(klass)
|
156
157
|
|
157
158
|
if klass.respond_to?(:pluralize)
|
data/lib/fastly/backend.rb
CHANGED
@@ -4,7 +4,7 @@ class Fastly
|
|
4
4
|
attr_accessor :service_id, :name, :address, :ipv4, :ipv6, :hostname, :use_ssl, :client_cert, :port,
|
5
5
|
:connect_timeout, :first_byte_timeout, :between_bytes_timeout, :error_threshold, :max_conn, :weight, :comment, :healthcheck, :auto_loadbalance, :request_condition,
|
6
6
|
:ssl_check_cert, :ssl_hostname, :ssl_cert_hostname, :ssl_sni_hostname, :min_tls_version, :max_tls_version, :ssl_ciphers,
|
7
|
-
:shield
|
7
|
+
:shield, :override_host
|
8
8
|
|
9
9
|
##
|
10
10
|
# :attr: service_id
|
data/lib/fastly/client.rb
CHANGED
@@ -27,9 +27,16 @@ class Fastly
|
|
27
27
|
|
28
28
|
return self unless fully_authed?
|
29
29
|
|
30
|
-
|
31
|
-
|
30
|
+
warn("DEPRECATION WARNING: Username/password authentication is deprecated
|
31
|
+
and will not be available starting September 2020;
|
32
|
+
please migrate to API tokens as soon as possible.")
|
32
33
|
|
34
|
+
# If full auth creds (user/pass) then log in and set a cookie
|
35
|
+
resp = http.post(
|
36
|
+
'/login',
|
37
|
+
make_params(user: user, password: password),
|
38
|
+
{'Content-Type' => 'application/x-www-form-urlencoded'}
|
39
|
+
)
|
33
40
|
if resp.kind_of?(Net::HTTPSuccess)
|
34
41
|
@cookie = resp['Set-Cookie']
|
35
42
|
else
|
@@ -59,8 +66,9 @@ class Fastly
|
|
59
66
|
|
60
67
|
def get(path, params = {})
|
61
68
|
extras = params.delete(:headers) || {}
|
69
|
+
include_auth = params.key?(:include_auth) ? params.delete(:include_auth) : true
|
62
70
|
path += "?#{make_params(params)}" unless params.empty?
|
63
|
-
resp = http.get(path, headers(extras))
|
71
|
+
resp = http.get(path, headers(extras, include_auth))
|
64
72
|
fail Error, resp.body unless resp.kind_of?(Net::HTTPSuccess)
|
65
73
|
JSON.parse(resp.body)
|
66
74
|
end
|
@@ -86,7 +94,8 @@ class Fastly
|
|
86
94
|
|
87
95
|
def delete(path, params = {})
|
88
96
|
extras = params.delete(:headers) || {}
|
89
|
-
|
97
|
+
include_auth = params.key?(:include_auth) ? params.delete(:include_auth) : true
|
98
|
+
resp = http.delete(path, headers(extras, include_auth))
|
90
99
|
resp.kind_of?(Net::HTTPSuccess)
|
91
100
|
end
|
92
101
|
|
@@ -132,16 +141,20 @@ class Fastly
|
|
132
141
|
|
133
142
|
def post_and_put(method, path, params = {})
|
134
143
|
extras = params.delete(:headers) || {}
|
144
|
+
include_auth = params.key?(:include_auth) ? params.delete(:include_auth) : true
|
135
145
|
query = make_params(params)
|
136
|
-
resp = http.send(method, path, query, headers(extras).merge('Content-Type' => 'application/x-www-form-urlencoded'))
|
146
|
+
resp = http.send(method, path, query, headers(extras, include_auth).merge('Content-Type' => 'application/x-www-form-urlencoded'))
|
137
147
|
fail Error, resp.body unless resp.kind_of?(Net::HTTPSuccess)
|
138
148
|
JSON.parse(resp.body)
|
139
149
|
end
|
140
150
|
|
141
|
-
def headers(extras={})
|
142
|
-
headers =
|
143
|
-
|
144
|
-
|
151
|
+
def headers(extras={}, include_auth=true)
|
152
|
+
headers = {}
|
153
|
+
# Some endpoints (POST /tokens) break if any auth headers including cookies are sent
|
154
|
+
if include_auth
|
155
|
+
headers['Cookie'] = cookie if fully_authed?
|
156
|
+
headers['Fastly-Key'] = api_key if api_key
|
157
|
+
end
|
145
158
|
headers.merge('Content-Accept' => 'application/json', 'User-Agent' => "fastly-ruby-v#{Fastly::VERSION}").merge(extras.keep_if {|k,v| !v.nil? })
|
146
159
|
end
|
147
160
|
|
data/lib/fastly/gem_version.rb
CHANGED
data/lib/fastly/service.rb
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
class Fastly
|
3
3
|
# Represents something you want to serve - this can be, for example, a whole web site, a Wordpress site, or just your image servers
|
4
4
|
class Service < Base
|
5
|
-
attr_accessor :id, :customer_id, :name, :comment
|
5
|
+
attr_accessor :id, :customer_id, :name, :comment
|
6
|
+
attr_writer :versions
|
6
7
|
|
7
8
|
@versions = []
|
8
9
|
|
data/lib/fastly/token.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Token object
|
4
|
+
class Fastly
|
5
|
+
class Token < Base
|
6
|
+
attr_accessor :id, :access_token, :user_id, :services, :name, :scope, :created_at, :last_used_at, :expires_at, :ip, :user_agent
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def self.get_path(*_args)
|
11
|
+
'/tokens'
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.post_path(*_args)
|
15
|
+
'/tokens'
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.delete_path(opts)
|
19
|
+
"/tokens/#{opts.id}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def new_token(opts)
|
24
|
+
opts[:username] = client.user
|
25
|
+
opts[:password] = client.password
|
26
|
+
opts[:include_auth] = false
|
27
|
+
|
28
|
+
token = create(Token, opts)
|
29
|
+
token.nil? ? nil : token
|
30
|
+
end
|
31
|
+
|
32
|
+
def customer_tokens(opts)
|
33
|
+
hash = client.get("/customer/#{opts[:customer_id]}/tokens")
|
34
|
+
hash.map { |token_hash| Token.new(token_hash, Fastly::Fetcher) }
|
35
|
+
end
|
36
|
+
end
|
data/test/fastly/client_test.rb
CHANGED
@@ -12,7 +12,7 @@ describe Fastly::Client do
|
|
12
12
|
}
|
13
13
|
end
|
14
14
|
|
15
|
-
it 'does not
|
15
|
+
it 'does not set the user/pass if they are not provided' do
|
16
16
|
client = Fastly::Client.new(api_key: api_key)
|
17
17
|
|
18
18
|
assert_equal api_key, client.api_key
|
@@ -29,6 +29,13 @@ describe Fastly::Client do
|
|
29
29
|
assert_equal "Invalid auth credentials. Check username/password.", e.message
|
30
30
|
end
|
31
31
|
|
32
|
+
it 'surfaces a deprecation message when a username or password is provided' do
|
33
|
+
stub_request(:any, /api.fastly.com/).
|
34
|
+
to_return(body: JSON.generate(i: "dont care"), status: 200)
|
35
|
+
|
36
|
+
assert_output('', /DEPRECATION WARNING:/) { Fastly::Client.new(user: user, password: pass) }
|
37
|
+
end
|
38
|
+
|
32
39
|
it 'initializes an http client' do
|
33
40
|
client = Fastly::Client.new(api_key: api_key)
|
34
41
|
|
@@ -98,6 +105,25 @@ describe Fastly::Client do
|
|
98
105
|
assert_equal resp.class, Hash
|
99
106
|
assert_includes resp, "i"
|
100
107
|
end
|
108
|
+
|
109
|
+
it 'can make a POST without auth if asked to do so' do
|
110
|
+
stub_request(:post, /api.fastly.com/).
|
111
|
+
with(headers: {
|
112
|
+
'Accept'=>'*/*',
|
113
|
+
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
114
|
+
'Content-Accept'=>'application/json',
|
115
|
+
'Content-Type'=>'application/x-www-form-urlencoded',
|
116
|
+
#'Fastly-Key'=>'notasecreteither',
|
117
|
+
'User-Agent'=> /fastly-ruby/
|
118
|
+
}).
|
119
|
+
to_return(body: JSON.generate(i: "dont care"), status: 200)
|
120
|
+
|
121
|
+
resp = client.post(
|
122
|
+
'/service/blah',
|
123
|
+
{include_auth: false}
|
124
|
+
)
|
125
|
+
end
|
126
|
+
|
101
127
|
end
|
102
128
|
|
103
129
|
describe 'get_stats' do
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
describe Fastly::Token do
|
4
|
+
|
5
|
+
let(:elevated_fastly) { Fastly.new(user: 'test@example.com', password: 'password') }
|
6
|
+
let(:fastly) { Fastly.new(api_key:'my_api_key') }
|
7
|
+
|
8
|
+
before {
|
9
|
+
stub_request(:post, "#{Fastly::Client::DEFAULT_URL}/login").to_return(body: '{}', status: 200, headers: { 'Set-Cookie' => 'tasty!' })
|
10
|
+
}
|
11
|
+
|
12
|
+
describe '#fastly' do
|
13
|
+
|
14
|
+
it 'cannot create itself because POST /tokens must have no auth headers)' do
|
15
|
+
stub_request(:post, "https://api.fastly.com/tokens").
|
16
|
+
with(
|
17
|
+
body: {"name"=>"name_of_token", "scope"=>"token_scope such_as purge_all purge_select", "services"=>"service_id_that_token_can_access"},
|
18
|
+
headers: {
|
19
|
+
'Accept'=>'*/*',
|
20
|
+
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
21
|
+
'Content-Accept'=>'application/json',
|
22
|
+
'Content-Type'=>'application/x-www-form-urlencoded',
|
23
|
+
'Cookie'=>'tasty!',
|
24
|
+
'User-Agent'=> /fastly-ruby/
|
25
|
+
}).
|
26
|
+
to_return(status: 403, body: '{"msg":"You must POST /sudo to access this endpoint"}', headers: {})
|
27
|
+
|
28
|
+
assert_raises(Fastly::Error,'{"msg":"You must POST /sudo to access this endpoint"}') do
|
29
|
+
elevated_fastly.create_token(
|
30
|
+
name: 'name_of_token',
|
31
|
+
services: 'service_id_that_token_can_access',
|
32
|
+
scope: 'token_scope such_as purge_all purge_select'
|
33
|
+
)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'can create a new token only if there are no auth headers' do
|
38
|
+
response_body = %q(
|
39
|
+
{
|
40
|
+
"id": "5Yo3XXnrQpjc20u0ybrf2g",
|
41
|
+
"access_token": "YOUR_FASTLY_TOKEN",
|
42
|
+
"user_id": "4y5K5trZocEAQYkesWlk7M",
|
43
|
+
"services": ["service_id_that_token_can_access"],
|
44
|
+
"name": "name_of_token",
|
45
|
+
"scope": "optional token_scope such_as purge_all purge_select",
|
46
|
+
"created_at": "2016-06-22T03:19:48+00:00",
|
47
|
+
"last_used_at": "2016-06-22T03:19:48+00:00",
|
48
|
+
"expires_at": "2016-07-28T19:24:50+00:00",
|
49
|
+
"ip": "127.17.202.173",
|
50
|
+
"user_agent": "fastly-ruby-v2.4.0"
|
51
|
+
}
|
52
|
+
)
|
53
|
+
|
54
|
+
stub_request(:post, "https://api.fastly.com/tokens").
|
55
|
+
with(
|
56
|
+
body: {"name"=>"name_of_token", "password"=>"password", "scope"=>"optional token_scope such_as purge_all purge_select", "services"=>"service_id_that_token_can_access", "username"=>"test@example.com"},
|
57
|
+
headers: {
|
58
|
+
'Accept'=>'*/*',
|
59
|
+
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
60
|
+
'Content-Accept'=>'application/json',
|
61
|
+
'Content-Type'=>'application/x-www-form-urlencoded',
|
62
|
+
'User-Agent'=> /fastly-ruby/
|
63
|
+
}).
|
64
|
+
to_return(status: 200, body: response_body, headers: {})
|
65
|
+
|
66
|
+
token = elevated_fastly.new_token(
|
67
|
+
name: 'name_of_token',
|
68
|
+
services: 'service_id_that_token_can_access',
|
69
|
+
scope: 'optional token_scope such_as purge_all purge_select'
|
70
|
+
)
|
71
|
+
assert_equal token.id, '5Yo3XXnrQpjc20u0ybrf2g'
|
72
|
+
assert_equal token.user_id, '4y5K5trZocEAQYkesWlk7M'
|
73
|
+
assert_equal token.services[0], 'service_id_that_token_can_access'
|
74
|
+
assert_equal token.name, 'name_of_token'
|
75
|
+
assert_equal token.scope, 'optional token_scope such_as purge_all purge_select'
|
76
|
+
assert_equal token.created_at, '2016-06-22T03:19:48+00:00'
|
77
|
+
assert_equal token.last_used_at, '2016-06-22T03:19:48+00:00'
|
78
|
+
assert_equal token.expires_at, '2016-07-28T19:24:50+00:00'
|
79
|
+
assert_equal token.ip, '127.17.202.173'
|
80
|
+
assert_equal token.user_agent, 'fastly-ruby-v2.4.0'
|
81
|
+
assert_equal token.access_token, 'YOUR_FASTLY_TOKEN'
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'would delete a token' do
|
85
|
+
stub_request(:delete, "https://api.fastly.com/tokens/").
|
86
|
+
with(
|
87
|
+
headers: {
|
88
|
+
'Accept'=>'*/*',
|
89
|
+
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
90
|
+
'Content-Accept'=>'application/json',
|
91
|
+
'Fastly-Key'=>'my_api_key',
|
92
|
+
'User-Agent'=> /fastly-ruby/
|
93
|
+
}).
|
94
|
+
to_return(status: 204, body: "", headers: {})
|
95
|
+
|
96
|
+
token = Fastly::Token.new({acess_token: 'my_api_key'}, Fastly::Fetcher)
|
97
|
+
fastly.delete_token(token)
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'would list all the tokens belonging to a token' do
|
101
|
+
stub_request(:get, "https://api.fastly.com/tokens").
|
102
|
+
with(
|
103
|
+
headers: {
|
104
|
+
'Accept'=>'*/*',
|
105
|
+
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
106
|
+
'Content-Accept'=>'application/json',
|
107
|
+
'Fastly-Key'=>'my_api_key',
|
108
|
+
'User-Agent'=> /fastly-ruby/
|
109
|
+
}).
|
110
|
+
to_return(status: 200, body: "[]", headers: {})
|
111
|
+
|
112
|
+
fastly.list_tokens()
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'would list all the tokens belonging to a customer' do
|
116
|
+
stub_request(:get, "https://api.fastly.com/customer/customer_account_number/tokens").
|
117
|
+
with(
|
118
|
+
headers: {
|
119
|
+
'Accept'=>'*/*',
|
120
|
+
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
121
|
+
'Content-Accept'=>'application/json',
|
122
|
+
'Fastly-Key'=>'my_api_key',
|
123
|
+
'User-Agent'=> /fastly-ruby/
|
124
|
+
}).
|
125
|
+
to_return(status: 200, body: "[]", headers: {})
|
126
|
+
|
127
|
+
fastly.customer_tokens({customer_id: 'customer_account_number'})
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|
data/test/helper.rb
CHANGED
data/test/token_test.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
# Testing client components related to tokens
|
4
|
+
class Fastly
|
5
|
+
describe 'TokenTest' do
|
6
|
+
let(:opts) { login_opts(:both) }
|
7
|
+
let(:fastly) { Fastly.new(opts) }
|
8
|
+
|
9
|
+
let(:service_name) { "fastly-test-service-#{random_string}" }
|
10
|
+
let(:service) { fastly.create_service(:name => service_name) }
|
11
|
+
let(:current_customer) { fastly.current_customer }
|
12
|
+
|
13
|
+
def create_a_test_token(name, service, scope)
|
14
|
+
fastly.new_token(
|
15
|
+
name: name,
|
16
|
+
services: service,
|
17
|
+
scope: scope
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'creates a new token' do
|
22
|
+
token = create_a_test_token('name_vi',service.id,'purge_all purge_select')
|
23
|
+
assert_equal token.name, 'name_vi'
|
24
|
+
assert_equal token.services[0], service.id
|
25
|
+
assert_equal token.scope, 'purge_all purge_select'
|
26
|
+
fastly.delete_token(token)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'deletes a token by passed-in token' do
|
30
|
+
token = create_a_test_token('name_vi',service.id,'purge_all purge_select')
|
31
|
+
|
32
|
+
tokens = fastly.customer_tokens({customer_id: current_customer.id})
|
33
|
+
before_count = tokens.count
|
34
|
+
|
35
|
+
fastly.delete_token(token)
|
36
|
+
|
37
|
+
tokens = fastly.customer_tokens({customer_id: current_customer.id})
|
38
|
+
after_count = tokens.count
|
39
|
+
|
40
|
+
assert_equal 1, before_count - after_count
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'returns a list of tokens belonging to the customer or to the auth token' do
|
44
|
+
@token_i = create_a_test_token('name_i',service.id,'purge_all purge_select')
|
45
|
+
@token_ii = create_a_test_token('name_ii',service.id,'purge_all purge_select')
|
46
|
+
@token_iii = create_a_test_token('name_iii',service.id,'purge_all purge_select')
|
47
|
+
@token_iv = create_a_test_token('name_iv',service.id,'purge_all purge_select')
|
48
|
+
@token_v = create_a_test_token('name_v',service.id,'purge_all purge_select')
|
49
|
+
|
50
|
+
tokens = fastly.customer_tokens({customer_id: current_customer.id})
|
51
|
+
assert tokens.count > 4
|
52
|
+
|
53
|
+
tokens = fastly.list_tokens
|
54
|
+
assert tokens.count > 4
|
55
|
+
|
56
|
+
fastly.delete_token(@token_i)
|
57
|
+
fastly.delete_token(@token_ii)
|
58
|
+
fastly.delete_token(@token_iii)
|
59
|
+
fastly.delete_token(@token_iv)
|
60
|
+
fastly.delete_token(@token_v)
|
61
|
+
fastly.delete_service(service)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fastly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3
|
4
|
+
version: 2.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fastly
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Client library for the Fastly acceleration system
|
14
14
|
email:
|
@@ -21,6 +21,7 @@ executables:
|
|
21
21
|
extensions: []
|
22
22
|
extra_rdoc_files: []
|
23
23
|
files:
|
24
|
+
- ".env.example"
|
24
25
|
- ".gitignore"
|
25
26
|
- ".rubocop.yml"
|
26
27
|
- ".travis.yml"
|
@@ -68,6 +69,7 @@ files:
|
|
68
69
|
- lib/fastly/snippet.rb
|
69
70
|
- lib/fastly/sumologic_logging.rb
|
70
71
|
- lib/fastly/syslog.rb
|
72
|
+
- lib/fastly/token.rb
|
71
73
|
- lib/fastly/user.rb
|
72
74
|
- lib/fastly/util.rb
|
73
75
|
- lib/fastly/vcl.rb
|
@@ -81,12 +83,14 @@ files:
|
|
81
83
|
- test/fastly/customer_test.rb
|
82
84
|
- test/fastly/dictionary_test.rb
|
83
85
|
- test/fastly/syslog_test.rb
|
86
|
+
- test/fastly/token_test.rb
|
84
87
|
- test/fastly/util_test.rb
|
85
88
|
- test/full_login_test.rb
|
86
89
|
- test/helper.rb
|
87
90
|
- test/missing_api_key_test.rb
|
88
91
|
- test/stats_test.rb
|
89
92
|
- test/test_helper.rb
|
93
|
+
- test/token_test.rb
|
90
94
|
homepage: http://github.com/fastly/fastly-ruby
|
91
95
|
licenses:
|
92
96
|
- MIT
|
@@ -106,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
110
|
- !ruby/object:Gem::Version
|
107
111
|
version: '0'
|
108
112
|
requirements: []
|
109
|
-
rubygems_version: 3.0.
|
113
|
+
rubygems_version: 3.0.6
|
110
114
|
signing_key:
|
111
115
|
specification_version: 4
|
112
116
|
summary: Client library for the Fastly acceleration system
|
@@ -120,9 +124,11 @@ test_files:
|
|
120
124
|
- test/fastly/customer_test.rb
|
121
125
|
- test/fastly/dictionary_test.rb
|
122
126
|
- test/fastly/syslog_test.rb
|
127
|
+
- test/fastly/token_test.rb
|
123
128
|
- test/fastly/util_test.rb
|
124
129
|
- test/full_login_test.rb
|
125
130
|
- test/helper.rb
|
126
131
|
- test/missing_api_key_test.rb
|
127
132
|
- test/stats_test.rb
|
128
133
|
- test/test_helper.rb
|
134
|
+
- test/token_test.rb
|