indexmap 0.6.0 → 0.7.0
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/CHANGELOG.md +3 -5
- data/README.md +92 -22
- data/lib/indexmap/configuration.rb +3 -6
- data/lib/indexmap/creator.rb +22 -35
- data/lib/indexmap/index_now_configuration.rb +12 -5
- data/lib/indexmap/output.rb +3 -5
- data/lib/indexmap/parser.rb +26 -14
- data/lib/indexmap/pinger/base.rb +5 -1
- data/lib/indexmap/pinger/google.rb +2 -2
- data/lib/indexmap/pinger/index_now.rb +21 -24
- data/lib/indexmap/storage/active_storage.rb +105 -0
- data/lib/indexmap/storage/file.rb +11 -0
- data/lib/indexmap/storage/filesystem.rb +77 -0
- data/lib/indexmap/storage/memory.rb +61 -0
- data/lib/indexmap/task_runner.rb +8 -8
- data/lib/indexmap/validator.rb +42 -30
- data/lib/indexmap/version.rb +1 -1
- data/lib/indexmap/writer.rb +2 -9
- data/lib/indexmap.rb +4 -1
- data/lib/tasks/indexmap_tasks.rake +5 -5
- data/test/indexmap/configuration_test.rb +98 -129
- data/test/indexmap/parser_test.rb +44 -3
- data/test/indexmap/pinger/google_test.rb +101 -123
- data/test/indexmap/pinger/index_now_test.rb +148 -179
- data/test/indexmap/storage_test.rb +123 -0
- data/test/indexmap/task_runner_test.rb +92 -63
- data/test/indexmap/validator_test.rb +96 -92
- data/test/indexmap/writer_test.rb +63 -74
- metadata +6 -3
- data/lib/indexmap/path.rb +0 -42
- data/test/indexmap/path_test.rb +0 -28
|
@@ -8,41 +8,49 @@ class IndexmapConfigurationTest < Minitest::Test
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def test_writer_builds_from_configured_callables
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
config.base_url = -> { "https://example.com" }
|
|
16
|
-
config.public_path = -> { public_path }
|
|
17
|
-
config.sections = -> do
|
|
18
|
-
[Indexmap::Section.new(filename: "sitemap-pages.xml", entries: [Indexmap::Entry.new(loc: "https://example.com/")])]
|
|
19
|
-
end
|
|
11
|
+
Indexmap.configure do |config|
|
|
12
|
+
config.base_url = -> { "https://example.com" }
|
|
13
|
+
config.sections = -> do
|
|
14
|
+
[Indexmap::Section.new(filename: "sitemap-pages.xml", entries: [Indexmap::Entry.new(loc: "https://example.com/")])]
|
|
20
15
|
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
files = Indexmap.configuration.writer.write
|
|
21
19
|
|
|
22
|
-
|
|
20
|
+
assert_includes files.find { |file| file.filename == "sitemap.xml" }.body, "<loc>https://example.com/sitemap-pages.xml</loc>"
|
|
21
|
+
assert_includes files.find { |file| file.filename == "sitemap-pages.xml" }.body, "<loc>https://example.com/</loc>"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_create_writes_to_configured_storage
|
|
25
|
+
storage = Indexmap::Storage::Memory.new
|
|
23
26
|
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
Indexmap.configure do |config|
|
|
28
|
+
config.base_url = "https://example.com"
|
|
29
|
+
config.storage = storage
|
|
30
|
+
config.sections = [
|
|
31
|
+
Indexmap::Section.new(filename: "sitemap-pages.xml", entries: [Indexmap::Entry.new(loc: "https://example.com/")])
|
|
32
|
+
]
|
|
26
33
|
end
|
|
34
|
+
|
|
35
|
+
files = Indexmap.create
|
|
36
|
+
|
|
37
|
+
assert_equal ["sitemap-pages.xml", "sitemap.xml"], files
|
|
38
|
+
assert_includes storage.read("sitemap.xml"), "<loc>https://example.com/sitemap-pages.xml</loc>"
|
|
39
|
+
assert_includes storage.read("sitemap-pages.xml"), "<loc>https://example.com/</loc>"
|
|
27
40
|
end
|
|
28
41
|
|
|
29
42
|
def test_writer_builds_single_file_writer_from_configured_entries
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
Indexmap.
|
|
34
|
-
|
|
35
|
-
config.public_path = public_path
|
|
36
|
-
config.format = :single_file
|
|
37
|
-
config.entries = -> { [Indexmap::Entry.new(loc: "https://example.com/")] }
|
|
38
|
-
end
|
|
43
|
+
Indexmap.configure do |config|
|
|
44
|
+
config.base_url = "https://example.com"
|
|
45
|
+
config.format = :single_file
|
|
46
|
+
config.entries = -> { [Indexmap::Entry.new(loc: "https://example.com/")] }
|
|
47
|
+
end
|
|
39
48
|
|
|
40
|
-
|
|
49
|
+
files = Indexmap.configuration.writer.write
|
|
41
50
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
end
|
|
51
|
+
assert_equal ["sitemap.xml"], files.map(&:filename)
|
|
52
|
+
assert_includes files.fetch(0).body, "<urlset"
|
|
53
|
+
assert_includes files.fetch(0).body, "<loc>https://example.com/</loc>"
|
|
46
54
|
end
|
|
47
55
|
|
|
48
56
|
def test_writer_raises_without_base_url
|
|
@@ -83,141 +91,102 @@ class IndexmapConfigurationTest < Minitest::Test
|
|
|
83
91
|
config.google.credentials = -> { "{\"type\":\"service_account\"}" }
|
|
84
92
|
config.google.property = -> { "sc-domain:example.com" }
|
|
85
93
|
config.index_now.key = -> { "example-key" }
|
|
94
|
+
config.index_now.key_filename = -> { "index-now-key.txt" }
|
|
86
95
|
config.index_now.max_urls_per_request = -> { 250 }
|
|
96
|
+
config.index_now.write_key_file = -> { false }
|
|
87
97
|
end
|
|
88
98
|
|
|
89
99
|
assert_equal "{\"type\":\"service_account\"}", Indexmap.configuration.google.credentials
|
|
90
100
|
assert_equal "sc-domain:example.com", Indexmap.configuration.google.property
|
|
91
101
|
assert_equal "example-key", Indexmap.configuration.index_now.key
|
|
102
|
+
assert_equal "index-now-key.txt", Indexmap.configuration.index_now.key_filename
|
|
92
103
|
assert_equal 250, Indexmap.configuration.index_now.max_urls_per_request
|
|
104
|
+
refute Indexmap.configuration.index_now.write_key_file?
|
|
93
105
|
end
|
|
94
106
|
|
|
95
|
-
def
|
|
96
|
-
|
|
97
|
-
public_path = Pathname(dir)
|
|
98
|
-
|
|
99
|
-
Indexmap.configure do |config|
|
|
100
|
-
config.base_url = "https://example.com"
|
|
101
|
-
config.public_path = public_path
|
|
102
|
-
config.output :reports do |output|
|
|
103
|
-
output.sections = [
|
|
104
|
-
Indexmap::Section.new(
|
|
105
|
-
filename: "sitemap-reports.xml",
|
|
106
|
-
entries: [Indexmap::Entry.new(loc: "https://example.com/reports")]
|
|
107
|
-
)
|
|
108
|
-
]
|
|
109
|
-
end
|
|
110
|
-
end
|
|
107
|
+
def test_index_now_key_file_writing_defaults_to_configured_key_presence
|
|
108
|
+
config = Indexmap::Configuration.new
|
|
111
109
|
|
|
112
|
-
|
|
110
|
+
refute config.index_now.write_key_file?
|
|
113
111
|
|
|
114
|
-
|
|
115
|
-
public_path.join("sitemap-reports.xml"),
|
|
116
|
-
public_path.join("sitemap.xml")
|
|
117
|
-
], files
|
|
118
|
-
assert_includes public_path.join("sitemap.xml").read, "https://example.com/sitemap-reports.xml"
|
|
119
|
-
end
|
|
120
|
-
end
|
|
112
|
+
config.index_now.key = "1234567890abcdef1234567890abcdef"
|
|
121
113
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
public_path = Pathname(dir)
|
|
125
|
-
|
|
126
|
-
Indexmap.configure do |config|
|
|
127
|
-
config.base_url = "https://example.com"
|
|
128
|
-
config.public_path = public_path
|
|
129
|
-
config.output :dynamic do |output|
|
|
130
|
-
output.sections = [
|
|
131
|
-
Indexmap::Section.new(
|
|
132
|
-
filename: "sitemap-dynamic.xml",
|
|
133
|
-
entries: [Indexmap::Entry.new(loc: "https://example.com/dynamic")]
|
|
134
|
-
)
|
|
135
|
-
]
|
|
136
|
-
end
|
|
137
|
-
end
|
|
114
|
+
assert config.index_now.write_key_file?
|
|
115
|
+
end
|
|
138
116
|
|
|
139
|
-
|
|
117
|
+
def test_index_now_key_file_writing_can_be_disabled_with_a_configured_key
|
|
118
|
+
config = Indexmap::Configuration.new
|
|
119
|
+
config.index_now.key = "1234567890abcdef1234567890abcdef"
|
|
120
|
+
config.index_now.write_key_file = false
|
|
140
121
|
|
|
141
|
-
|
|
142
|
-
public_path.join("sitemap-dynamic.xml"),
|
|
143
|
-
public_path.join("sitemap.xml")
|
|
144
|
-
], files
|
|
145
|
-
assert_includes public_path.join("sitemap-dynamic.xml").read, "https://example.com/dynamic"
|
|
146
|
-
assert_includes public_path.join("sitemap.xml").read, "https://example.com/sitemap-dynamic.xml"
|
|
147
|
-
end
|
|
122
|
+
refute config.index_now.write_key_file?
|
|
148
123
|
end
|
|
149
124
|
|
|
150
|
-
def
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
config.public_path = public_path
|
|
159
|
-
config.sections = [
|
|
125
|
+
def test_named_outputs_inherit_configuration_defaults
|
|
126
|
+
storage = Indexmap::Storage::Memory.new
|
|
127
|
+
|
|
128
|
+
Indexmap.configure do |config|
|
|
129
|
+
config.base_url = "https://example.com"
|
|
130
|
+
config.storage = storage
|
|
131
|
+
config.output :reports do |output|
|
|
132
|
+
output.sections = [
|
|
160
133
|
Indexmap::Section.new(
|
|
161
|
-
filename: "sitemap-
|
|
162
|
-
entries: [Indexmap::Entry.new(loc: "https://example.com/
|
|
134
|
+
filename: "sitemap-reports.xml",
|
|
135
|
+
entries: [Indexmap::Entry.new(loc: "https://example.com/reports")]
|
|
163
136
|
)
|
|
164
137
|
]
|
|
165
138
|
end
|
|
139
|
+
end
|
|
166
140
|
|
|
167
|
-
|
|
141
|
+
files = Indexmap.create(:reports)
|
|
168
142
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
assert_equal "old child", public_path.join("sitemap-pages.xml").read
|
|
172
|
-
end
|
|
143
|
+
assert_equal ["sitemap-reports.xml", "sitemap.xml"], files
|
|
144
|
+
assert_includes storage.read("sitemap.xml"), "https://example.com/sitemap-reports.xml"
|
|
173
145
|
end
|
|
174
146
|
|
|
175
147
|
def test_create_writes_single_file_named_output_without_default_index
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
]
|
|
188
|
-
end
|
|
148
|
+
storage = Indexmap::Storage::Memory.new
|
|
149
|
+
|
|
150
|
+
Indexmap.configure do |config|
|
|
151
|
+
config.base_url = "https://example.com"
|
|
152
|
+
config.storage = storage
|
|
153
|
+
config.output :dynamic do |output|
|
|
154
|
+
output.format = :single_file
|
|
155
|
+
output.index_filename = "sitemap-dynamic.xml"
|
|
156
|
+
output.entries = [
|
|
157
|
+
Indexmap::Entry.new(loc: "https://example.com/dynamic")
|
|
158
|
+
]
|
|
189
159
|
end
|
|
160
|
+
end
|
|
190
161
|
|
|
191
|
-
|
|
162
|
+
files = Indexmap.create(:dynamic)
|
|
192
163
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
end
|
|
164
|
+
assert_equal ["sitemap-dynamic.xml"], files
|
|
165
|
+
refute storage.exist?("sitemap.xml")
|
|
166
|
+
assert_includes storage.read("sitemap-dynamic.xml"), "https://example.com/dynamic"
|
|
197
167
|
end
|
|
198
168
|
|
|
199
|
-
def
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
Indexmap.configure do |config|
|
|
205
|
-
config.base_url = "https://example.com"
|
|
206
|
-
config.public_path = public_path
|
|
207
|
-
config.output :dynamic do |output|
|
|
208
|
-
output.format = :single_file
|
|
209
|
-
output.index_filename = "sitemap-dynamic.xml"
|
|
210
|
-
output.entries = [
|
|
211
|
-
Indexmap::Entry.new(loc: "https://example.com/dynamic?utm_source=test")
|
|
212
|
-
]
|
|
213
|
-
end
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
error = assert_raises(Indexmap::ValidationError) { Indexmap.create(:dynamic) }
|
|
169
|
+
def test_create_preserves_existing_files_when_validation_fails
|
|
170
|
+
storage = Indexmap::Storage::Memory.new
|
|
171
|
+
storage.write("sitemap.xml", "old index")
|
|
172
|
+
storage.write("sitemap-pages.xml", "old child")
|
|
217
173
|
|
|
218
|
-
|
|
219
|
-
|
|
174
|
+
Indexmap.configure do |config|
|
|
175
|
+
config.base_url = "https://example.com"
|
|
176
|
+
config.storage = storage
|
|
177
|
+
config.sections = [
|
|
178
|
+
Indexmap::Section.new(
|
|
179
|
+
filename: "sitemap-pages.xml",
|
|
180
|
+
entries: [Indexmap::Entry.new(loc: "https://example.com/about?utm_source=test")]
|
|
181
|
+
)
|
|
182
|
+
]
|
|
220
183
|
end
|
|
184
|
+
|
|
185
|
+
error = assert_raises(Indexmap::ValidationError) { Indexmap.create }
|
|
186
|
+
|
|
187
|
+
assert_match "Parameterized sitemap URLs detected", error.message
|
|
188
|
+
assert_equal "old index", storage.read("sitemap.xml")
|
|
189
|
+
assert_equal "old child", storage.read("sitemap-pages.xml")
|
|
221
190
|
end
|
|
222
191
|
|
|
223
192
|
def test_after_create_requires_a_block
|
|
@@ -16,7 +16,7 @@ class IndexmapParserTest < Minitest::Test
|
|
|
16
16
|
XML
|
|
17
17
|
)
|
|
18
18
|
|
|
19
|
-
parser = Indexmap::Parser.new(
|
|
19
|
+
parser = Indexmap::Parser.new(source: "https://www.example.com/sitemap.xml")
|
|
20
20
|
|
|
21
21
|
assert_equal ["/", "/pages/features"], parser.paths
|
|
22
22
|
end
|
|
@@ -44,7 +44,7 @@ class IndexmapParserTest < Minitest::Test
|
|
|
44
44
|
XML
|
|
45
45
|
)
|
|
46
46
|
|
|
47
|
-
parser = Indexmap::Parser.new(
|
|
47
|
+
parser = Indexmap::Parser.new(source: "https://www.example.com/sitemap.xml")
|
|
48
48
|
|
|
49
49
|
assert_equal ["/tools/google-reviews-calculator"], parser.paths
|
|
50
50
|
assert_equal ["https://www.reviato.com/tools/google-reviews-calculator"], parser.urls(base_url: "https://www.reviato.com")
|
|
@@ -73,9 +73,50 @@ class IndexmapParserTest < Minitest::Test
|
|
|
73
73
|
XML
|
|
74
74
|
)
|
|
75
75
|
|
|
76
|
-
parser = Indexmap::Parser.new(
|
|
76
|
+
parser = Indexmap::Parser.new(source: "http://localhost:3001/sitemap.xml", rebase_remote_children: true)
|
|
77
77
|
|
|
78
78
|
assert_equal ["/pages/pricing"], parser.paths
|
|
79
79
|
assert_equal ["http://localhost:3001/pages/pricing"], parser.urls(base_url: "http://localhost:3001")
|
|
80
80
|
end
|
|
81
|
+
|
|
82
|
+
def test_parses_storage_sitemap_index_with_directory_keys
|
|
83
|
+
storage = Indexmap::Storage::Memory.new
|
|
84
|
+
storage.write("sitemaps/sitemap.xml", <<~XML)
|
|
85
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
86
|
+
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
87
|
+
<sitemap><loc>https://www.example.com/sitemaps/content.xml</loc></sitemap>
|
|
88
|
+
</sitemapindex>
|
|
89
|
+
XML
|
|
90
|
+
storage.write("sitemaps/content.xml", <<~XML)
|
|
91
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
92
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
93
|
+
<url><loc>https://www.example.com/pages/features</loc></url>
|
|
94
|
+
</urlset>
|
|
95
|
+
XML
|
|
96
|
+
|
|
97
|
+
parser = Indexmap::Parser.new(source: "sitemaps/sitemap.xml", storage: storage)
|
|
98
|
+
|
|
99
|
+
assert_equal ["/pages/features"], parser.paths
|
|
100
|
+
assert_equal ["sitemaps/content.xml"], parser.entries.map(&:source_sitemap)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def test_parses_relative_child_sitemaps_from_parent_directory
|
|
104
|
+
storage = Indexmap::Storage::Memory.new
|
|
105
|
+
storage.write("sitemaps/sitemap.xml", <<~XML)
|
|
106
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
107
|
+
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
108
|
+
<sitemap><loc>content.xml</loc></sitemap>
|
|
109
|
+
</sitemapindex>
|
|
110
|
+
XML
|
|
111
|
+
storage.write("sitemaps/content.xml", <<~XML)
|
|
112
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
113
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
114
|
+
<url><loc>https://www.example.com/pages/pricing</loc></url>
|
|
115
|
+
</urlset>
|
|
116
|
+
XML
|
|
117
|
+
|
|
118
|
+
parser = Indexmap::Parser.new(source: "sitemaps/sitemap.xml", storage: storage)
|
|
119
|
+
|
|
120
|
+
assert_equal ["/pages/pricing"], parser.paths
|
|
121
|
+
end
|
|
81
122
|
end
|
|
@@ -28,167 +28,145 @@ class IndexmapPingerGoogleTest < Minitest::Test
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def test_pings_google_for_each_sitemap_file
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
service = FakeWebmastersService.new(site_urls: ["sc-domain:example.com"])
|
|
41
|
-
builder_calls = []
|
|
42
|
-
credentials_builder = lambda do |credentials:, scope:|
|
|
43
|
-
builder_calls << [credentials, scope]
|
|
44
|
-
:fake_authorizer
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
result = Indexmap::Pinger::Google.new(
|
|
48
|
-
configuration: configuration,
|
|
49
|
-
service: service,
|
|
50
|
-
credentials_builder: credentials_builder
|
|
51
|
-
).ping
|
|
52
|
-
|
|
53
|
-
assert_equal [["{\"type\":\"service_account\"}", "https://www.googleapis.com/auth/webmasters"]], builder_calls
|
|
54
|
-
assert_equal :fake_authorizer, service.authorization
|
|
55
|
-
assert_equal ["sc-domain:example.com", "https://www.example.com/sitemap.xml"], service.submitted
|
|
56
|
-
assert_equal :submitted, result[:status]
|
|
57
|
-
assert_equal 1, result[:sitemap_count]
|
|
58
|
-
assert_equal 0, result[:url_count]
|
|
59
|
-
assert_equal 1, service.list_sites_calls
|
|
31
|
+
configuration = configuration_with(storage: storage_with("sitemap.xml" => "<sitemapindex/>"))
|
|
32
|
+
configuration.google.credentials = "{\"type\":\"service_account\"}"
|
|
33
|
+
|
|
34
|
+
service = FakeWebmastersService.new(site_urls: ["sc-domain:example.com"])
|
|
35
|
+
builder_calls = []
|
|
36
|
+
credentials_builder = lambda do |credentials:, scope:|
|
|
37
|
+
builder_calls << [credentials, scope]
|
|
38
|
+
:fake_authorizer
|
|
60
39
|
end
|
|
40
|
+
|
|
41
|
+
result = Indexmap::Pinger::Google.new(
|
|
42
|
+
configuration: configuration,
|
|
43
|
+
service: service,
|
|
44
|
+
credentials_builder: credentials_builder
|
|
45
|
+
).ping
|
|
46
|
+
|
|
47
|
+
assert_equal [["{\"type\":\"service_account\"}", "https://www.googleapis.com/auth/webmasters"]], builder_calls
|
|
48
|
+
assert_equal :fake_authorizer, service.authorization
|
|
49
|
+
assert_equal ["sc-domain:example.com", "https://www.example.com/sitemap.xml"], service.submitted
|
|
50
|
+
assert_equal :submitted, result[:status]
|
|
51
|
+
assert_equal 1, result[:sitemap_count]
|
|
52
|
+
assert_equal 0, result[:url_count]
|
|
53
|
+
assert_equal 1, service.list_sites_calls
|
|
61
54
|
end
|
|
62
55
|
|
|
63
56
|
def test_reports_unique_url_count_from_submitted_sitemaps
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
public_path.join("sitemap.xml").write(<<~XML)
|
|
57
|
+
storage = storage_with(
|
|
58
|
+
"sitemap.xml" => <<~XML,
|
|
67
59
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
68
60
|
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
69
61
|
<sitemap><loc>https://www.example.com/sitemap-pages.xml</loc></sitemap>
|
|
70
62
|
<sitemap><loc>https://www.example.com/sitemap-posts.xml</loc></sitemap>
|
|
71
63
|
</sitemapindex>
|
|
72
64
|
XML
|
|
73
|
-
|
|
65
|
+
"sitemap-pages.xml" => <<~XML,
|
|
74
66
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
75
67
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
76
68
|
<url><loc>https://www.example.com/</loc></url>
|
|
77
69
|
<url><loc>https://www.example.com/about</loc></url>
|
|
78
70
|
</urlset>
|
|
79
71
|
XML
|
|
80
|
-
|
|
72
|
+
"sitemap-posts.xml" => <<~XML
|
|
81
73
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
82
74
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
83
75
|
<url><loc>https://www.example.com/about</loc></url>
|
|
84
76
|
<url><loc>https://www.example.com/blog</loc></url>
|
|
85
77
|
</urlset>
|
|
86
78
|
XML
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
["sc-domain:example.com", "https://www.example.com/sitemap.xml"]
|
|
107
|
-
], service.submissions
|
|
108
|
-
end
|
|
79
|
+
)
|
|
80
|
+
configuration = configuration_with(storage: storage)
|
|
81
|
+
configuration.google.credentials = "{\"type\":\"service_account\"}"
|
|
82
|
+
|
|
83
|
+
service = FakeWebmastersService.new(site_urls: ["sc-domain:example.com"])
|
|
84
|
+
result = Indexmap::Pinger::Google.new(
|
|
85
|
+
configuration: configuration,
|
|
86
|
+
service: service,
|
|
87
|
+
credentials_builder: ->(**) { :fake_authorizer }
|
|
88
|
+
).ping
|
|
89
|
+
|
|
90
|
+
assert_equal :submitted, result[:status]
|
|
91
|
+
assert_equal 3, result[:sitemap_count]
|
|
92
|
+
assert_equal 3, result[:url_count]
|
|
93
|
+
assert_equal [
|
|
94
|
+
["sc-domain:example.com", "https://www.example.com/sitemap-pages.xml"],
|
|
95
|
+
["sc-domain:example.com", "https://www.example.com/sitemap-posts.xml"],
|
|
96
|
+
["sc-domain:example.com", "https://www.example.com/sitemap.xml"]
|
|
97
|
+
], service.submissions
|
|
109
98
|
end
|
|
110
99
|
|
|
111
100
|
def test_skips_google_ping_when_credentials_are_missing
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
public_path.join("sitemap.xml").write("<sitemapindex/>")
|
|
115
|
-
|
|
116
|
-
configuration = Indexmap::Configuration.new
|
|
117
|
-
configuration.base_url = "https://www.example.com"
|
|
118
|
-
configuration.public_path = public_path
|
|
101
|
+
configuration = configuration_with(storage: storage_with("sitemap.xml" => "<sitemapindex/>"))
|
|
102
|
+
service = FakeWebmastersService.new(site_urls: ["sc-domain:example.com"])
|
|
119
103
|
|
|
120
|
-
|
|
104
|
+
result = Indexmap::Pinger::Google.new(configuration: configuration, service: service).ping
|
|
121
105
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
assert_nil service.submitted
|
|
125
|
-
assert_equal({status: :skipped, reason: :missing_credentials}, result)
|
|
126
|
-
end
|
|
106
|
+
assert_nil service.submitted
|
|
107
|
+
assert_equal({status: :skipped, reason: :missing_credentials}, result)
|
|
127
108
|
end
|
|
128
109
|
|
|
129
110
|
def test_reports_missing_sitemap_files
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
service
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
assert_equal({status: :skipped, reason: :no_sitemaps}, result)
|
|
144
|
-
assert_nil service.submitted
|
|
145
|
-
end
|
|
111
|
+
configuration = configuration_with
|
|
112
|
+
configuration.google.credentials = "{\"type\":\"service_account\"}"
|
|
113
|
+
|
|
114
|
+
service = FakeWebmastersService.new(site_urls: ["sc-domain:example.com"])
|
|
115
|
+
result = Indexmap::Pinger::Google.new(
|
|
116
|
+
configuration: configuration,
|
|
117
|
+
service: service,
|
|
118
|
+
credentials_builder: ->(**) { :fake_authorizer }
|
|
119
|
+
).ping
|
|
120
|
+
|
|
121
|
+
assert_equal({status: :skipped, reason: :no_sitemaps}, result)
|
|
122
|
+
assert_nil service.submitted
|
|
146
123
|
end
|
|
147
124
|
|
|
148
125
|
def test_reports_google_authorization_failure
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
configuration
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
).ping
|
|
164
|
-
|
|
165
|
-
assert_equal :failed, result[:status]
|
|
166
|
-
assert_equal 1, result[:failures].count
|
|
167
|
-
assert_equal :unauthorized, result[:failures].first[:reason]
|
|
168
|
-
assert_nil service.submitted
|
|
169
|
-
end
|
|
126
|
+
configuration = configuration_with(storage: storage_with("sitemap.xml" => "<sitemapindex/>"))
|
|
127
|
+
configuration.google.credentials = "{\"type\":\"service_account\"}"
|
|
128
|
+
|
|
129
|
+
service = FakeWebmastersService.new(site_urls: ["sc-domain:not-example.org"])
|
|
130
|
+
result = Indexmap::Pinger::Google.new(
|
|
131
|
+
configuration: configuration,
|
|
132
|
+
service: service,
|
|
133
|
+
credentials_builder: ->(**) { :fake_authorizer }
|
|
134
|
+
).ping
|
|
135
|
+
|
|
136
|
+
assert_equal :failed, result[:status]
|
|
137
|
+
assert_equal 1, result[:failures].count
|
|
138
|
+
assert_equal :unauthorized, result[:failures].first[:reason]
|
|
139
|
+
assert_nil service.submitted
|
|
170
140
|
end
|
|
171
141
|
|
|
172
142
|
def test_google_authorization_requires_exact_property_match
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
143
|
+
configuration = configuration_with(storage: storage_with("sitemap.xml" => "<sitemapindex/>"))
|
|
144
|
+
configuration.google.credentials = "{\"type\":\"service_account\"}"
|
|
145
|
+
|
|
146
|
+
service = FakeWebmastersService.new(site_urls: ["sc-domain:myexample.com"])
|
|
147
|
+
result = Indexmap::Pinger::Google.new(
|
|
148
|
+
configuration: configuration,
|
|
149
|
+
service: service,
|
|
150
|
+
credentials_builder: ->(**) { :fake_authorizer }
|
|
151
|
+
).ping
|
|
152
|
+
|
|
153
|
+
assert_equal :failed, result[:status]
|
|
154
|
+
assert_equal :unauthorized, result[:failures].first[:reason]
|
|
155
|
+
assert_nil service.submitted
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
private
|
|
176
159
|
|
|
177
|
-
|
|
160
|
+
def configuration_with(storage: Indexmap::Storage::Memory.new(public_url: "https://www.example.com"))
|
|
161
|
+
Indexmap::Configuration.new.tap do |configuration|
|
|
178
162
|
configuration.base_url = "https://www.example.com"
|
|
179
|
-
configuration.
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
credentials_builder: ->(**) { :fake_authorizer }
|
|
187
|
-
).ping
|
|
188
|
-
|
|
189
|
-
assert_equal :failed, result[:status]
|
|
190
|
-
assert_equal :unauthorized, result[:failures].first[:reason]
|
|
191
|
-
assert_nil service.submitted
|
|
163
|
+
configuration.storage = storage
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def storage_with(files)
|
|
168
|
+
Indexmap::Storage::Memory.new(public_url: "https://www.example.com").tap do |storage|
|
|
169
|
+
files.each { |filename, body| storage.write(filename, body) }
|
|
192
170
|
end
|
|
193
171
|
end
|
|
194
172
|
end
|