diff --git a/History.markdown b/History.markdown index 61a482c..02aefda 100644 --- a/History.markdown +++ b/History.markdown @@ -1,3 +1,9 @@ +## HEAD + +### Minor Enhancements + + * Allow disabling of all network accesses (#285) + ## 2.16.1 / 2023-12-22 ### Bug Fixes diff --git a/docs/configuration.md b/docs/configuration.md index 9725677..fb7373a 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -44,6 +44,7 @@ Some `site.github` values can be overridden by environment variables. - `PAGES_GITHUB_HOSTNAME` – the `site.github.hostname` (default: `github.com`) - `PAGES_PAGES_HOSTNAME` – the `site.github.pages_hostname` (default: `github.io`) - `NO_NETRC` – set if you don't want the fallback to `~/.netrc` +- `PAGES_DISABLE_NETWORK` – set to prevent all network accesses (disables features that need to access the GitHub API) ## Using with GitHub Enterprise diff --git a/lib/jekyll-github-metadata/client.rb b/lib/jekyll-github-metadata/client.rb index f655152..aab378b 100644 --- a/lib/jekyll-github-metadata/client.rb +++ b/lib/jekyll-github-metadata/client.rb @@ -110,15 +110,19 @@ def authenticated? def internet_connected? return @internet_connected if defined?(@internet_connected) - require "resolv" - begin - Resolv::DNS.open do |dns| - dns.timeouts = 2 - dns.getaddress("api.github.com") - end - @internet_connected = true - rescue Resolv::ResolvError + if ENV["PAGES_DISABLE_NETWORK"] @internet_connected = false + else + require "resolv" + begin + Resolv::DNS.open do |dns| + dns.timeouts = 2 + dns.getaddress("api.github.com") + end + @internet_connected = true + rescue Resolv::ResolvError + @internet_connected = false + end end end diff --git a/spec/client_spec.rb b/spec/client_spec.rb index 0d56158..7ab97f2 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -38,4 +38,20 @@ subject.contributors("jekyll/github-metadata") end.to raise_error(described_class::BadCredentialsError) end + + it "supresses network accesses if requested" do + WebMock.disable_net_connect! + + with_env("PAGES_DISABLE_NETWORK", "1") do + expect(subject.contributors("jekyll/github-metadata")).to be(false) + end + end + + it "allows network accesses by default" do + WebMock.disable_net_connect! + + expect do + subject.contributors("jekyll/github-metadata") + end.to raise_error(WebMock::NetConnectNotAllowedError) + end end pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy