cloudflare 4.2.0 → 4.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9da58bc3e8cf7394296aafbe26d50731d145f1587df2ecd940057c01de31585c
4
- data.tar.gz: 0b8523d30369c61c1fa5aaf1d749daa9a05c03f36c1a9aa898bb5782e662fa6c
3
+ metadata.gz: 9dcc42587b1325b8ec2935b4b2bc93024dbf217928050c0ff84ce7623f805722
4
+ data.tar.gz: e2c287268b345cd3f2e9edbd116180117b5ea7ea7d7156e7b53ac4f6c5f95e09
5
5
  SHA512:
6
- metadata.gz: 8079f41055721191fd999e1b4e948d0061bf5e710503940c07d4125a315c812cda8e5603cc891e50671f5992dbc75ab1e65d6a297c9f6656db0317e85784cc35
7
- data.tar.gz: 9f6ac470ada76aea32143026ac1b7923b76b0b50775a362759817dd7fc3118b792d6ad36f4dcd2829e3b3faba097f3c1072e01db3d1a9d21ab5c653285421683
6
+ metadata.gz: 9a82ec080141604eafce382d2bf3f7986974e4c80ba108c0aa900ffafbb79b90b32e604ae497baa842e667878e3bbcfbf452848f24d448ff1935eecdfccb59bc
7
+ data.tar.gz: e6137b9c6dbaf3dd81265a2e5b07c7e40b392a08abf49318ae4f3822c8edb14c71e1e7fa7650e24cd9b91009b27e9ded0fe53f4be235d26e4a57e5c64415cc84
@@ -29,7 +29,7 @@ module Cloudflare
29
29
  module RSpec
30
30
  module Connection
31
31
  end
32
-
32
+
33
33
  RSpec.shared_context Connection do
34
34
  include_context Async::RSpec::Reactor
35
35
 
@@ -22,5 +22,5 @@
22
22
  # THE SOFTWARE.
23
23
 
24
24
  module Cloudflare
25
- VERSION = '4.2.0'
25
+ VERSION = '4.2.1'
26
26
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudflare
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcin Prokop
8
8
  - Samuel Williams
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-11-11 00:00:00.000000000 Z
12
+ date: 2020-07-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: async-rest
@@ -39,20 +39,6 @@ dependencies:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
- - !ruby/object:Gem::Dependency
43
- name: covered
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- version: '0'
49
- type: :development
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: '0'
56
42
  - !ruby/object:Gem::Dependency
57
43
  name: bundler
58
44
  requirement: !ruby/object:Gem::Requirement
@@ -68,7 +54,7 @@ dependencies:
68
54
  - !ruby/object:Gem::Version
69
55
  version: '0'
70
56
  - !ruby/object:Gem::Dependency
71
- name: rake
57
+ name: covered
72
58
  requirement: !ruby/object:Gem::Requirement
73
59
  requirements:
74
60
  - - ">="
@@ -95,21 +81,12 @@ dependencies:
95
81
  - - "~>"
96
82
  - !ruby/object:Gem::Version
97
83
  version: '3.6'
98
- description:
84
+ description:
99
85
  email:
100
- - marcin@prokop.co
101
- - samuel.williams@oriontransfer.co.nz
102
86
  executables: []
103
87
  extensions: []
104
88
  extra_rdoc_files: []
105
89
  files:
106
- - ".gitignore"
107
- - ".rspec"
108
- - ".travis.yml"
109
- - Gemfile
110
- - README.md
111
- - Rakefile
112
- - cloudflare.gemspec
113
90
  - lib/cloudflare.rb
114
91
  - lib/cloudflare/accounts.rb
115
92
  - lib/cloudflare/connection.rb
@@ -126,20 +103,11 @@ files:
126
103
  - lib/cloudflare/user.rb
127
104
  - lib/cloudflare/version.rb
128
105
  - lib/cloudflare/zones.rb
129
- - spec/cloudflare/accounts_spec.rb
130
- - spec/cloudflare/custom_hostname/ssl_attribute/settings_spec.rb
131
- - spec/cloudflare/custom_hostname/ssl_attribute_spec.rb
132
- - spec/cloudflare/custom_hostnames_spec.rb
133
- - spec/cloudflare/dns_spec.rb
134
- - spec/cloudflare/firewall_spec.rb
135
- - spec/cloudflare/kv/namespaces_spec.rb
136
- - spec/cloudflare/zone_spec.rb
137
- - spec/spec_helper.rb
138
- homepage: https://github.com/b4k3r/cloudflare
106
+ homepage: https://github.com/socketry/cloudflare
139
107
  licenses:
140
108
  - MIT
141
109
  metadata: {}
142
- post_install_message:
110
+ post_install_message:
143
111
  rdoc_options: []
144
112
  require_paths:
145
113
  - lib
@@ -147,24 +115,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
115
  requirements:
148
116
  - - ">="
149
117
  - !ruby/object:Gem::Version
150
- version: 2.0.0
118
+ version: '2.5'
151
119
  required_rubygems_version: !ruby/object:Gem::Requirement
152
120
  requirements:
153
121
  - - ">="
154
122
  - !ruby/object:Gem::Version
155
123
  version: '0'
156
124
  requirements: []
157
- rubygems_version: 3.0.6
158
- signing_key:
125
+ rubygems_version: 3.1.2
126
+ signing_key:
159
127
  specification_version: 4
160
128
  summary: A Ruby wrapper for the Cloudflare API.
161
- test_files:
162
- - spec/cloudflare/accounts_spec.rb
163
- - spec/cloudflare/custom_hostname/ssl_attribute/settings_spec.rb
164
- - spec/cloudflare/custom_hostname/ssl_attribute_spec.rb
165
- - spec/cloudflare/custom_hostnames_spec.rb
166
- - spec/cloudflare/dns_spec.rb
167
- - spec/cloudflare/firewall_spec.rb
168
- - spec/cloudflare/kv/namespaces_spec.rb
169
- - spec/cloudflare/zone_spec.rb
170
- - spec/spec_helper.rb
129
+ test_files: []
data/.gitignore DELETED
@@ -1,14 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
-
11
- # rspec failure tracking
12
- .rspec_status
13
- .covered.db
14
- .env
data/.rspec DELETED
@@ -1,4 +0,0 @@
1
- --format documentation
2
- --backtrace
3
- --warnings
4
- --require spec_helper
@@ -1,35 +0,0 @@
1
- language: ruby
2
- dist: xenial
3
- cache: bundler
4
-
5
- addons:
6
- apt:
7
- packages:
8
- - squid
9
-
10
- matrix:
11
- include:
12
- - rvm: 2.4
13
- - rvm: 2.5
14
- - rvm: 2.6
15
- - rvm: 2.6
16
- env: COVERAGE=BriefSummary,Coveralls
17
- - rvm: jruby-head
18
- env: JRUBY_OPTS="--debug -X+O"
19
- - rvm: truffleruby
20
- - rvm: ruby-head
21
- - rvm: 2.6
22
- env: CLOUDFLARE_PROXY=http://localhost:3128
23
- before_script: sudo service squid start
24
- - rvm: jruby-head
25
- env: JRUBY_OPTS="--debug -X+O" CLOUDFLARE_PROXY=http://localhost:3128
26
- before_script: sudo service squid start
27
- allow_failures:
28
- - rvm: ruby-head
29
- - rvm: jruby-head
30
- - rvm: truffleruby
31
-
32
- env:
33
- global:
34
- - CLOUDFLARE_TEST_ZONE_MANAGEMENT=true
35
- - secure: c5yG7N1r9nYuw47Y90jGeoHNvkL59AAC55dtPAhKP+gjXWW8hKbntj3oj+lVkxEqzRpzEQgYZzUElrP+6mJnb20ldclZg03L56243tMtVEcpGOx/MFhnIBkx3kKu1H6ydKKMxieHxjsLQ3vnpcIZ3p0skTQjYbjdu607tjbyg7s=
data/Gemfile DELETED
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- # Specify your gem's dependencies in cloudflare.gemspec
6
- gemspec
7
-
8
- gem 'async-http', '~> 0.48', '>= 0.48.2'
9
-
10
- group :development do
11
- gem 'pry'
12
- gem 'pry-coolline'
13
- end
14
-
15
- group :test do
16
- gem 'coveralls', require: false
17
- gem 'simplecov'
18
- gem 'sinatra'
19
- gem 'webmock'
20
- end
data/README.md DELETED
@@ -1,117 +0,0 @@
1
- # Cloudflare
2
-
3
- It is a Ruby wrapper for the Cloudflare V4 API. It provides a light weight wrapper using `RestClient::Resource`. The wrapper functionality is limited to zones and DNS records at this time, *PRs welcome*.
4
-
5
- [![Build Status](https://secure.travis-ci.org/socketry/cloudflare.svg)](http://travis-ci.org/socketry/cloudflare)
6
- [![Coverage Status](https://coveralls.io/repos/socketry/cloudflare/badge.svg)](https://coveralls.io/r/socketry/cloudflare)
7
-
8
- ## Installation
9
-
10
- Add this line to your application's Gemfile:
11
-
12
- ```ruby
13
- gem 'cloudflare'
14
- ```
15
-
16
- And then execute:
17
-
18
- ```
19
- $ bundle
20
- ```
21
-
22
- Or install it yourself as:
23
-
24
- ```
25
- $ gem install cloudflare
26
- ```
27
-
28
- ## Usage
29
-
30
- Here are some basic examples. For more details, refer to the code and specs.
31
-
32
- ```ruby
33
- require 'cloudflare'
34
-
35
- # Grab some details from somewhere:
36
- email = ENV['CLOUDFLARE_EMAIL']
37
- key = ENV['CLOUDFLARE_KEY']
38
-
39
- Cloudflare.connect(key: key, email: email) do |connection|
40
- # Get all available zones:
41
- zones = connection.zones
42
-
43
- # Get a specific zone:
44
- zone = connection.zones.find_by_id("...")
45
- zone = connection.zones.find_by_name("example.com")
46
-
47
- # Get DNS records for a given zone:
48
- dns_records = zone.dns_records
49
-
50
- # Show some details of the DNS record:
51
- dns_record = dns_records.first
52
- puts dns_record.name
53
-
54
- # Add a DNS record. Here we add an A record for `batman.example.com`:
55
- zone = zones.find_by_name("example.com")
56
- zone.dns_records.create('A', 'batman', '1.2.3.4', proxied: false)
57
-
58
- # Get firewall rules:
59
- all_rules = zone.firewall_rules
60
-
61
- # Block an ip:
62
- rule = zone.firewall_rules.set('block', '1.2.3.4', notes: "ssh dictionary attack")
63
- end
64
- ```
65
-
66
- ### Using a Bearer Token
67
-
68
- You can read more about [bearer tokens here](https://blog.cloudflare.com/api-tokens-general-availability/). This allows you to limit priviledges.
69
-
70
- ```ruby
71
- require 'cloudflare'
72
-
73
- token = 'a_generated_api_token'
74
-
75
- Cloudflare.connect(token: token) do |connection|
76
- # ...
77
- end
78
- ```
79
-
80
- ## Contributing
81
-
82
- 1. Fork it
83
- 2. Create your feature branch (`git checkout -b my-new-feature`)
84
- 3. Commit your changes (`git commit -am 'Add some feature'`)
85
- 4. Push to the branch (`git push origin my-new-feature`)
86
- 5. Create new Pull Request
87
-
88
- ## See Also
89
-
90
- - [Cloudflare::DNS::Update](https://github.com/ioquatix/cloudflare-dns-update) - A dynamic DNS updater based on this gem.
91
- - [Rubyflare](https://github.com/trev/rubyflare) - Another implementation.
92
-
93
- ## License
94
-
95
- Released under the MIT license.
96
-
97
- Copyright, 2018, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
98
- Copyright, 2017, by [David Rosenbloom](http://artifactory.com).
99
- Copyright, 2012, 2014, by [Marcin Prokop](https://github.com/b4k3r).
100
-
101
- Permission is hereby granted, free of charge, to any person obtaining a copy
102
- of this software and associated documentation files (the "Software"), to deal
103
- in the Software without restriction, including without limitation the rights
104
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
105
- copies of the Software, and to permit persons to whom the Software is
106
- furnished to do so, subject to the following conditions:
107
-
108
- The above copyright notice and this permission notice shall be included in
109
- all copies or substantial portions of the Software.
110
-
111
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
112
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
113
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
114
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
115
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
116
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
117
- THE SOFTWARE.
data/Rakefile DELETED
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
5
-
6
- RSpec::Core::RakeTask.new(:test)
7
-
8
- task default: :test
9
-
10
- task :coverage do
11
- ENV['COVERAGE'] = 'y'
12
- end
13
-
14
- task :console do
15
- require_relative 'lib/cloudflare'
16
- require 'pry'
17
-
18
- email = ENV.fetch('CLOUDFLARE_EMAIL')
19
- key = ENV.fetch('CLOUDFLARE_KEY')
20
-
21
- Async.run do
22
- connection = Cloudflare.connect(key: key, email: email)
23
-
24
- binding.pry
25
- end
26
- end
@@ -1,32 +0,0 @@
1
-
2
- # frozen_string_literal: true
3
-
4
- require_relative 'lib/cloudflare/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'cloudflare'
8
- spec.version = Cloudflare::VERSION
9
- spec.platform = Gem::Platform::RUBY
10
-
11
- spec.summary = 'A Ruby wrapper for the Cloudflare API.'
12
- spec.authors = ['Marcin Prokop', 'Samuel Williams']
13
- spec.email = ['marcin@prokop.co', 'samuel.williams@oriontransfer.co.nz']
14
- spec.homepage = 'https://github.com/b4k3r/cloudflare'
15
- spec.licenses = ['MIT']
16
-
17
- spec.files = `git ls-files`.split("\n")
18
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
- spec.require_paths = ['lib']
21
-
22
- spec.required_ruby_version = '>= 2.0.0'
23
-
24
- spec.add_dependency 'async-rest', '~> 0.10.0'
25
-
26
- spec.add_development_dependency 'async-rspec'
27
-
28
- spec.add_development_dependency 'covered'
29
- spec.add_development_dependency 'bundler'
30
- spec.add_development_dependency 'rake'
31
- spec.add_development_dependency 'rspec', '~> 3.6'
32
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe Cloudflare::Accounts, order: :defined, timeout: 30 do
4
- include_context Cloudflare::Account
5
-
6
- before do
7
- account.id # Force a fetch if it hasn't happened yet
8
- end
9
-
10
- it 'can list existing accounts' do
11
- accounts = connection.accounts.to_a
12
- expect(accounts.any? {|a| a.id == account.id }).to be true
13
- end
14
-
15
- it 'can get a specific account' do
16
- expect(connection.accounts.find_by_id(account.id).id).to eq account.id
17
- end
18
-
19
- it 'can generate a representation for the KV namespace endpoint' do
20
- ns = connection.accounts.find_by_id(account.id).kv_namespaces
21
- expect(ns).to be_kind_of(Cloudflare::KV::Namespaces)
22
- expect(ns.resource.reference.path).to end_with("/#{account.id}/storage/kv/namespaces")
23
- end
24
- end
@@ -1,54 +0,0 @@
1
- RSpec.describe Cloudflare::CustomHostname::SSLAttribute::Settings do
2
-
3
- subject { described_class.new({}) }
4
-
5
- it 'has an accessor for ciphers' do
6
- ciphers = double
7
- expect(subject.ciphers).to be_nil
8
- subject.ciphers = ciphers
9
- expect(subject.ciphers).to be ciphers
10
- end
11
-
12
- it 'has a boolean accessor for http2' do
13
- expect(subject.http2).to be_nil
14
- expect(subject.http2?).to be false
15
- subject.http2 = true
16
- expect(subject.http2).to eq 'on'
17
- expect(subject.http2?).to be true
18
- subject.http2 = false
19
- expect(subject.http2).to eq 'off'
20
- expect(subject.http2?).to be false
21
- subject.http2 = 'on'
22
- expect(subject.http2).to eq 'on'
23
- expect(subject.http2?).to be true
24
- subject.http2 = 'off'
25
- expect(subject.http2).to eq 'off'
26
- expect(subject.http2?).to be false
27
- end
28
-
29
- it 'has an accessor for min_tls_version' do
30
- tls_version = double
31
- expect(subject.min_tls_version).to be_nil
32
- subject.min_tls_version = tls_version
33
- expect(subject.min_tls_version).to be tls_version
34
- end
35
-
36
- it 'has a boolean accessor for tls_1_3' do
37
- expect(subject.tls_1_3).to be_nil
38
- expect(subject.tls_1_3?).to be false
39
- subject.tls_1_3 = true
40
- expect(subject.tls_1_3).to eq 'on'
41
- expect(subject.tls_1_3?).to be true
42
- subject.tls_1_3 = false
43
- expect(subject.tls_1_3).to eq 'off'
44
- expect(subject.tls_1_3?).to be false
45
- subject.tls_1_3 = 'on'
46
- expect(subject.tls_1_3).to eq 'on'
47
- expect(subject.tls_1_3?).to be true
48
- subject.tls_1_3 = 'off'
49
- expect(subject.tls_1_3).to eq 'off'
50
- expect(subject.tls_1_3?).to be false
51
- end
52
-
53
-
54
- end
@@ -1,73 +0,0 @@
1
- RSpec.describe Cloudflare::CustomHostname::SSLAttribute do
2
-
3
- accessors = [:cname, :cname_target, :http_body, :http_url, :method, :status, :type, :validation_errors]
4
-
5
- let(:original_hash) { {} }
6
-
7
- subject { described_class.new(original_hash) }
8
-
9
- accessors.each do |key|
10
-
11
- it "has an accessor for the #{key} value" do
12
- test_value = double
13
- expect(subject.send(key)).to be_nil
14
- original_hash[key] = test_value
15
- expect(subject.send(key)).to be test_value
16
- end
17
-
18
- end
19
-
20
- it '#active? returns true when the status is "active" and false otherwise' do
21
- expect(subject.active?).to be false
22
- original_hash[:status] = 'initializing'
23
- expect(subject.active?).to be false
24
- original_hash[:status] = 'pending_validation'
25
- expect(subject.active?).to be false
26
- original_hash[:status] = 'pending_deployment'
27
- expect(subject.active?).to be false
28
- original_hash[:status] = 'active'
29
- expect(subject.active?).to be true
30
- end
31
-
32
- it '#pending_validation? returns true when the status is "pending_validation" and false otherwise' do
33
- expect(subject.pending_validation?).to be false
34
- original_hash[:status] = 'initializing'
35
- expect(subject.pending_validation?).to be false
36
- original_hash[:status] = 'active'
37
- expect(subject.pending_validation?).to be false
38
- original_hash[:status] = 'pending_deployment'
39
- expect(subject.pending_validation?).to be false
40
- original_hash[:status] = 'pending_validation'
41
- expect(subject.pending_validation?).to be true
42
- end
43
-
44
- describe '#settings' do
45
-
46
- it 'should return a Settings object' do
47
- expect(subject.settings).to be_kind_of Cloudflare::CustomHostname::SSLAttribute::Settings
48
- end
49
-
50
- it 'initailizes the settings object with the value from the settings key' do
51
- settings = { min_tls_version: double }
52
- original_hash[:settings] = settings
53
- expect(subject.settings.min_tls_version).to be settings[:min_tls_version]
54
- end
55
-
56
- it 'initializes the settings object with a new hash if the settings key does not exist' do
57
- expected_value = double
58
- expect(original_hash[:settings]).to be_nil
59
- expect(subject.settings.min_tls_version).to be_nil
60
- expect(original_hash[:settings]).not_to be_nil
61
- original_hash[:settings][:min_tls_version] = expected_value
62
- expect(subject.settings.min_tls_version).to be expected_value
63
- end
64
-
65
- it 'updates the stored hash with values set on the settings object' do
66
- expected_value = double
67
- expect(subject.settings.min_tls_version).to be_nil
68
- subject.settings.min_tls_version = expected_value
69
- expect(original_hash[:settings][:min_tls_version]).to be expected_value
70
- end
71
- end
72
-
73
- end
@@ -1,213 +0,0 @@
1
-
2
- RSpec.xdescribe Cloudflare::CustomHostnames, order: :defined, timeout: 30 do
3
- include_context Cloudflare::Zone
4
-
5
- let(:domain) { "www#{ENV['TRAVIS_JOB_ID'] || rand(1..5)}.ourtest.com" }
6
-
7
- let(:record) { @record = zone.custom_hostnames.create(domain) }
8
-
9
- let(:custom_origin) do
10
- id = rand(1...100)
11
- id += (job_id * 100) if job_id.positive?
12
- subdomain = "origin-#{id}"
13
- @dns_record = zone.dns_records.create("A", subdomain, "1.2.3.4") # This needs to exist or the calls will fail
14
- "#{subdomain}.#{zone.name}"
15
- end
16
-
17
- after do
18
- if defined? @record
19
- expect(@record.delete).to be_success
20
- end
21
-
22
- if defined? @dns_record
23
- expect(@dns_record.delete).to be_success
24
- end
25
- end
26
-
27
- it 'can create a custom hostname record' do
28
- expect(record).to be_kind_of Cloudflare::CustomHostname
29
- expect(record.custom_metadata).to be_nil
30
- expect(record.hostname).to eq domain
31
- expect(record.custom_origin).to be_nil
32
- expect(record.ssl.method).to eq 'http'
33
- expect(record.ssl.type).to eq 'dv'
34
- end
35
-
36
- it 'can create a custom hostname record with a custom origin' do
37
- begin
38
- @record = zone.custom_hostnames.create(domain, origin: custom_origin)
39
-
40
- expect(@record).to be_kind_of Cloudflare::CustomHostname
41
- expect(@record.custom_metadata).to be_nil
42
- expect(@record.hostname).to eq domain
43
- expect(@record.custom_origin).to eq custom_origin
44
- expect(@record.ssl.method).to eq 'http'
45
- expect(@record.ssl.type).to eq 'dv'
46
- rescue Cloudflare::RequestError => e
47
- if e.message.include?('custom origin server has not been granted')
48
- skip(e.message) # This currently doesn't work but might start eventually: https://github.com/socketry/async-rspec/issues/7
49
- else
50
- raise
51
- end
52
- end
53
- end
54
-
55
- it 'can create a custom hostname record with different ssl options' do
56
- @record = zone.custom_hostnames.create(domain, ssl: { method: 'cname' })
57
-
58
- expect(@record).to be_kind_of Cloudflare::CustomHostname
59
- expect(@record.custom_metadata).to be_nil
60
- expect(@record.hostname).to eq domain
61
- expect(@record.custom_origin).to be_nil
62
- expect(@record.ssl.method).to eq 'cname'
63
- expect(@record.ssl.type).to eq 'dv'
64
- end
65
-
66
- it 'can create a custom hostname record with additional metadata' do
67
- metadata = { a: rand(1..10) }
68
-
69
- begin
70
- @record = zone.custom_hostnames.create(domain, metadata: metadata)
71
-
72
- expect(@record).to be_kind_of Cloudflare::CustomHostname
73
- expect(@record.custom_metadata).to eq metadata
74
- expect(@record.hostname).to eq domain
75
- expect(@record.custom_origin).to be_nil
76
- expect(@record.ssl.method).to eq 'http'
77
- expect(@record.ssl.type).to eq 'dv'
78
- rescue Cloudflare::RequestError => e
79
- if e.message.include?('No custom metadata access has been allocated for this zone')
80
- skip(e.message) # This currently doesn't work but might start eventually: https://github.com/socketry/async-rspec/issues/7
81
- else
82
- raise
83
- end
84
- end
85
- end
86
-
87
- it 'can look up an existing custom hostname by the hostname or id' do
88
- expect(zone.custom_hostnames.find_by_hostname(record.hostname).id).to eq record.id
89
- expect(zone.custom_hostnames.find_by_id(record.id).id).to eq record.id
90
- end
91
-
92
- context 'with existing record' do
93
-
94
- it 'returns the hostname when calling #to_s' do
95
- expect(record.to_s).to eq domain
96
- end
97
-
98
- it 'can update metadata' do
99
- metadata = { c: rand(1..10) }
100
-
101
- expect(record.custom_metadata).to be_nil
102
-
103
- begin
104
- record.update_settings(metadata: metadata)
105
-
106
- # Make sure the existing object is updated
107
- expect(record.custom_metadata).to eq metadata
108
-
109
- # Verify that the server has the changes
110
- found_record = zone.custom_hostnames.find_by_id(record.id)
111
-
112
- expect(found_record.custom_metadata).to eq metadata
113
- expect(found_record.hostname).to eq domain
114
- expect(found_record.custom_origin).to be_nil
115
- rescue Cloudflare::RequestError => e
116
- if e.message.include?('No custom metadata access has been allocated for this zone')
117
- skip(e.message) # This currently doesn't work but might start eventually: https://github.com/socketry/async-rspec/issues/7
118
- else
119
- raise
120
- end
121
- end
122
- end
123
-
124
- it 'can update the custom origin' do
125
- expect(record.custom_origin).to be_nil
126
-
127
- begin
128
- record.update_settings(origin: custom_origin)
129
-
130
- # Make sure the existing object is updated
131
- expect(record.custom_origin).to eq custom_origin
132
-
133
- # Verify that the server has the changes
134
- found_record = zone.custom_hostnames.find_by_id(record.id)
135
-
136
- expect(found_record.custom_metadata).to be_nil
137
- expect(found_record.hostname).to eq domain
138
- expect(found_record.custom_origin).to eq custom_origin
139
- rescue Cloudflare::RequestError => e
140
- if e.message.include?('custom origin server has not been granted')
141
- skip(e.message) # This currently doesn't work but might start eventually: https://github.com/socketry/async-rspec/issues/7
142
- else
143
- raise
144
- end
145
- end
146
- end
147
-
148
- it 'can update ssl information' do
149
- expect(record.ssl.method).to eq 'http'
150
-
151
- record.update_settings(ssl: { method: 'cname', type: 'dv' })
152
-
153
- # Make sure the existing object is updated
154
- expect(record.ssl.method).to eq 'cname'
155
-
156
- # Verify that the server has the changes
157
- found_record = zone.custom_hostnames.find_by_id(record.id)
158
-
159
- expect(found_record.custom_metadata).to be_nil
160
- expect(found_record.hostname).to eq domain
161
- expect(found_record.custom_origin).to be_nil
162
- expect(found_record.ssl.method).to eq 'cname'
163
- end
164
-
165
- context 'has an ssl section' do
166
-
167
- it 'wraps it in an SSLAttributes object' do
168
- expect(record.ssl).to be_kind_of Cloudflare::CustomHostname::SSLAttribute
169
- end
170
-
171
- it 'has some helpers for commonly used keys' do
172
- # Make sure our values exist before we check to make sure that they are returned correctly
173
- expect(record.value[:ssl].values_at(:method, :http_body, :http_url).compact).not_to be_empty
174
- expect(record.ssl.method).to be record.value[:ssl][:method]
175
- expect(record.ssl.http_body).to be record.value[:ssl][:http_body]
176
- expect(record.ssl.http_url).to be record.value[:ssl][:http_url]
177
- end
178
-
179
- end
180
-
181
- describe '#ssl_active?' do
182
-
183
- it 'returns the result of calling ssl.active?' do
184
- expected_value = double
185
- expect(record.ssl).to receive(:active?).and_return(expected_value)
186
- expect(record).not_to receive(:send_patch)
187
- expect(record.ssl_active?).to be expected_value
188
- end
189
-
190
- it 'returns the result of calling ssl.active? without triggering an update if force_update is true and the ssl is not in the pending_validation state' do
191
- expected_value = double
192
- expect(record.ssl).to receive(:active?).and_return(expected_value)
193
- expect(record.ssl.method).not_to be_nil
194
- expect(record.ssl.type).not_to be_nil
195
- expect(record.ssl.pending_validation?).to be false
196
- expect(record).not_to receive(:send_patch).with(ssl: { method: record.ssl.method, type: record.ssl.type })
197
- expect(record.ssl_active?(true)).to be expected_value
198
- end
199
-
200
- it 'returns the result of calling ssl.active? after triggering an update if force_update is true and the ssl is in the pending_validation state' do
201
- expected_value = double
202
- expect(record.ssl).to receive(:active?).and_return(expected_value)
203
- expect(record.ssl.method).not_to be_nil
204
- expect(record.ssl.type).not_to be_nil
205
- record.value[:ssl][:status] = 'pending_validation'
206
- expect(record).to receive(:send_patch).with(ssl: { method: record.ssl.method, type: record.ssl.type })
207
- expect(record.ssl_active?(true)).to be expected_value
208
- end
209
-
210
- end
211
-
212
- end
213
- end
@@ -1,50 +0,0 @@
1
-
2
- require 'cloudflare/rspec/connection'
3
-
4
- RSpec.describe Cloudflare::DNS, order: :defined, timeout: 30 do
5
- include_context Cloudflare::Zone
6
-
7
- let(:subdomain) {"www#{ENV['TRAVIS_JOB_ID']}"}
8
-
9
- after do
10
- if defined? @record
11
- expect(@record.delete).to be_success
12
- end
13
- end
14
-
15
- context "new record" do
16
- it "can create dns record" do
17
- @record = zone.dns_records.create("A", subdomain, "1.2.3.4")
18
- expect(@record.type).to be == "A"
19
- expect(@record.name).to be_start_with subdomain
20
- expect(@record.content).to be == "1.2.3.4"
21
- end
22
-
23
- it "can create dns record with proxied option" do
24
- @record = zone.dns_records.create("A", subdomain, "1.2.3.4", proxied: true)
25
- expect(@record.type).to be == "A"
26
- expect(@record.name).to be_start_with subdomain
27
- expect(@record.content).to be == "1.2.3.4"
28
- expect(@record.proxied).to be_truthy
29
- end
30
- end
31
-
32
- context "with existing record" do
33
- let(:record) {@record = zone.dns_records.create("A", subdomain, "1.2.3.4")}
34
- it "can update dns content" do
35
- record.update_content("4.3.2.1")
36
- expect(record.content).to be == "4.3.2.1"
37
-
38
- fetched_record = zone.dns_records.find_by_name(record.name)
39
- expect(fetched_record.content).to be == record.content
40
- end
41
-
42
- it "can update dns content with proxied option" do
43
- record.update_content("4.3.2.1", proxied: true)
44
- expect(record.proxied).to be_truthy
45
-
46
- fetched_record = zone.dns_records.find_by_name(record.name)
47
- expect(fetched_record.proxied).to be_truthy
48
- end
49
- end
50
- end
@@ -1,48 +0,0 @@
1
-
2
- require 'cloudflare/rspec/connection'
3
-
4
- RSpec.describe Cloudflare::Firewall, order: :defined, timeout: 30 do
5
- include_context Cloudflare::Zone
6
-
7
- let(:notes) {'gemtest'}
8
-
9
- context "with several rules" do
10
- let(:allow_ip) {'123.123.123.123'}
11
- let(:block_ip) {'123.123.123.124'}
12
-
13
- before do
14
- zone.firewall_rules.each do |rule|
15
- rule.delete
16
- end
17
-
18
- zone.firewall_rules.set('whitelist', allow_ip)
19
- zone.firewall_rules.set('block', block_ip)
20
- end
21
-
22
- it 'should get all rules' do
23
- rules = zone.firewall_rules.to_a
24
-
25
- expect(rules.size).to be >= 2
26
- end
27
-
28
- it 'should get rules with specific value' do
29
- rules = zone.firewall_rules.each_by_value(allow_ip).to_a
30
-
31
- expect(rules.size).to be == 1
32
- end
33
- end
34
-
35
- %w[block challenge whitelist].each_with_index do |mode, index|
36
- it "should create a #{mode} rule" do
37
- value = "123.123.123.#{index}"
38
- rule = zone.firewall_rules.set(mode, value, notes: notes)
39
-
40
- expect(rule.mode).to be == mode
41
- expect(rule.configuration[:value]).to be == value
42
- expect(rule.configuration[:target]).to be == 'ip'
43
- expect(rule.notes).to be == notes
44
-
45
- rule.delete
46
- end
47
- end
48
- end
@@ -1,71 +0,0 @@
1
-
2
- RSpec.describe Cloudflare::KV::Namespaces, kv_spec: true, order: :defined, timeout: 30 do
3
- include_context Cloudflare::Account
4
-
5
- let(:namespace) { @namespace = account.kv_namespaces.create(namespace_title) }
6
- let(:namespace_title) { "Test NS ##{rand(1..100)}" }
7
-
8
- after do
9
- if defined? @namespace
10
- expect(@namespace.delete).to be_success
11
- end
12
- end
13
-
14
- it 'can create a namespace' do
15
- expect(namespace).to be_kind_of Cloudflare::KV::Namespace
16
- expect(namespace.id).not_to be_nil
17
- expect(namespace.title).to eq namespace_title
18
- end
19
-
20
- it 'can find a namespace by title' do
21
- namespace # Call this so that the namespace gets created
22
- expect(account.kv_namespaces.find_by_title(namespace_title).id).to eq namespace.id
23
- end
24
-
25
- it 'can rename the namespace' do
26
- new_title = "#{namespace_title}-#{rand(1..100)}"
27
- namespace.rename(new_title)
28
- expect(namespace.title).to eq new_title
29
- expect(account.kv_namespaces.find_by_title(new_title).id).to eq namespace.id
30
- expect(account.kv_namespaces.find_by_title(namespace_title)).to be_nil
31
- end
32
-
33
- it 'can store a key/value, read it back' do
34
- key = "key-#{rand(1..100)}"
35
- value = rand(100..999)
36
- namespace.write_value(key, value)
37
- expect(account.kv_namespaces.find_by_id(namespace.id).read_value(key)).to eq value.to_s
38
- end
39
-
40
- it 'can read a previously stored key' do
41
- key = "key-#{rand(1..100)}"
42
- value = rand(100..999)
43
- expect(account.kv_namespaces.find_by_id(namespace.id).write_value(key, value)).to be true
44
- expect(namespace.read_value(key)).to eq value.to_s
45
- end
46
-
47
- it 'can delete keys' do
48
- key = "key-#{rand(1..100)}"
49
- value = rand(100..999)
50
- expect(namespace.write_value(key, value)).to be true
51
- expect(namespace.read_value(key)).to eq value.to_s
52
- expect(namespace.delete_value(key)).to be true
53
- expect do
54
- account.kv_namespaces.find_by_id(namespace.id).read_value(key)
55
- end.to raise_error(Cloudflare::RequestError)
56
- end
57
-
58
- it 'can get the keys that exist in the namespace' do
59
- counter = 0
60
- keys = Array.new(rand(1..9)) { "key-#{counter += 1}" } # Keep this single digits so ordering works
61
- keys.each_with_index do |key, i|
62
- namespace.write_value(key, i)
63
- end
64
-
65
- saved_keys = account.kv_namespaces.find_by_id(namespace.id).keys.to_a
66
- expect(saved_keys.length).to eq keys.length
67
- saved_keys.each_with_index do |key, i|
68
- expect(key.name).to eq keys[i]
69
- end
70
- end
71
- end
@@ -1,27 +0,0 @@
1
-
2
- RSpec.describe Cloudflare::Zones, order: :defined, timeout: 30 do
3
- include_context Cloudflare::Zone
4
-
5
- if ENV['CLOUDFLARE_TEST_ZONE_MANAGEMENT'] == 'true'
6
- it "can delete existing domain if exists" do
7
- if zone = zones.find_by_name(name)
8
- expect(zone.delete).to be_success
9
- end
10
- end
11
-
12
- it "can create a zone" do
13
- zone = zones.create(name, account)
14
- expect(zone.value).to include(:id)
15
- end
16
- end
17
-
18
- it "can list zones" do
19
- matching_zones = zones.select{|zone| zone.name == name}
20
- expect(matching_zones).to_not be_empty
21
- end
22
-
23
- it "can get zone by name" do
24
- found_zone = zones.find_by_name(name)
25
- expect(found_zone.name).to be == name
26
- end
27
- end
@@ -1,85 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- AUTH_EMAIL = ENV['CLOUDFLARE_EMAIL']
4
- AUTH_KEY = ENV['CLOUDFLARE_KEY']
5
-
6
- if AUTH_EMAIL.nil? || AUTH_EMAIL.empty? || AUTH_KEY.nil? || AUTH_KEY.empty?
7
- puts 'Please make sure you have defined CLOUDFLARE_EMAIL and CLOUDFLARE_KEY in your environment'
8
- puts 'You can also specify CLOUDFLARE_ZONE_NAME to test with your own zone and'
9
- puts 'CLOUDFLARE_ACCOUNT_ID to use a specific account'
10
- exit(1)
11
- end
12
-
13
- ACCOUNT_ID = ENV['CLOUDFLARE_ACCOUNT_ID']
14
- NAMES = ['testing', 'horse', 'cat', 'dog', 'fish', 'dolphin', 'lion', 'tiger'].freeze
15
- JOB_ID = ENV.fetch('TRAVIS_JOB_ID', 0).to_i
16
- ZONE_NAME = ENV['CLOUDFLARE_ZONE_NAME'] || "#{NAMES[JOB_ID % NAMES.size]}.com"
17
-
18
- require 'covered/rspec'
19
- require 'async/rspec'
20
-
21
- require 'cloudflare/rspec/connection'
22
- require 'cloudflare/zones'
23
-
24
- RSpec.shared_context Cloudflare::Account do
25
- include_context Cloudflare::RSpec::Connection
26
-
27
- let(:account) do
28
- if ACCOUNT_ID
29
- connection.accounts.find_by_id(ACCOUNT_ID)
30
- else
31
- connection.accounts.first
32
- end
33
- end
34
-
35
- end
36
-
37
- RSpec.shared_context Cloudflare::Zone do
38
- include_context Cloudflare::Account
39
-
40
- let(:job_id) { JOB_ID }
41
- let(:names) { NAMES.dup }
42
- let(:name) { ZONE_NAME.dup }
43
-
44
- let(:zones) {connection.zones}
45
-
46
- let(:zone) {@zone = zones.find_by_name(name) || zones.create(name, account)}
47
-
48
- # after do
49
- # if defined? @zone
50
- # @zone.delete
51
- # end
52
- # end
53
- end
54
-
55
- RSpec.configure do |config|
56
- # Enable flags like --only-failures and --next-failure
57
- config.example_status_persistence_file_path = '.rspec_status'
58
-
59
- config.expect_with :rspec do |c|
60
- c.syntax = :expect
61
- end
62
-
63
- disabled_specs = {}
64
-
65
- # Check for features the current account has enabled
66
- Cloudflare.connect(key: AUTH_KEY, email: AUTH_EMAIL) do |conn|
67
- begin
68
- account = if ACCOUNT_ID
69
- conn.accounts.find_by_id(ACCOUNT_ID)
70
- else
71
- conn.accounts.first
72
- end
73
- account.kv_namespaces.to_a
74
- rescue Cloudflare::RequestError => e
75
- if e.message.include?('your account is not entitled')
76
- puts 'Disabling KV specs due to no access'
77
- disabled_specs[:kv_spec] = true
78
- else
79
- raise
80
- end
81
- end
82
- end
83
-
84
- config.filter_run_excluding disabled_specs unless disabled_specs.empty?
85
- end