File tree Expand file tree Collapse file tree 3 files changed +29
-8
lines changed
lib/jekyll-github-metadata Expand file tree Collapse file tree 3 files changed +29
-8
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ Some `site.github` values can be overridden by environment variables.
4444- `PAGES_GITHUB_HOSTNAME` – the `site.github.hostname` (default : ` github.com` )
4545- `PAGES_PAGES_HOSTNAME` – the `site.github.pages_hostname` (default : ` github.io` )
4646- ` NO_NETRC` – set if you don't want the fallback to `~/.netrc`
47+ - ` PAGES_DISABLE_NETWORK` – set to prevent all network accesses (disables features that need to access the GitHub API)
4748
4849# # Using with GitHub Enterprise
4950
Original file line number Diff line number Diff line change @@ -110,15 +110,19 @@ def authenticated?
110110 def internet_connected?
111111 return @internet_connected if defined? ( @internet_connected )
112112
113- require "resolv"
114- begin
115- Resolv ::DNS . open do |dns |
116- dns . timeouts = 2
117- dns . getaddress ( "api.github.com" )
118- end
119- @internet_connected = true
120- rescue Resolv ::ResolvError
113+ if ENV [ "PAGES_DISABLE_NETWORK" ]
121114 @internet_connected = false
115+ else
116+ require "resolv"
117+ begin
118+ Resolv ::DNS . open do |dns |
119+ dns . timeouts = 2
120+ dns . getaddress ( "api.github.com" )
121+ end
122+ @internet_connected = true
123+ rescue Resolv ::ResolvError
124+ @internet_connected = false
125+ end
122126 end
123127 end
124128
Original file line number Diff line number Diff line change 3838 subject . contributors ( "jekyll/github-metadata" )
3939 end . to raise_error ( described_class ::BadCredentialsError )
4040 end
41+
42+ it "supresses network accesses if requested" do
43+ WebMock . disable_net_connect!
44+
45+ with_env ( "PAGES_DISABLE_NETWORK" , "1" ) do
46+ expect ( subject . contributors ( "jekyll/github-metadata" ) ) . to be ( false )
47+ end
48+ end
49+
50+ it "allows network accesses by default" do
51+ WebMock . disable_net_connect!
52+
53+ expect do
54+ subject . contributors ( "jekyll/github-metadata" )
55+ end . to raise_error ( WebMock ::NetConnectNotAllowedError )
56+ end
4157end
You can’t perform that action at this time.
0 commit comments