Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only set allowedOrigin when needed #248

Merged
merged 19 commits into from
Sep 19, 2022
Merged
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"changelog": "standard-version -a --skip.tag=true --skip.commit=true --skip.bump=true"
},
"devDependencies": {
"axe-test-fixtures": "github:dequelabs/axe-test-fixtures#v1",
"axe-test-fixtures": "github:dequelabs/axe-test-fixtures",
"standard-version": "^9.0.0"
}
}
44 changes: 43 additions & 1 deletion packages/axe-core-api/e2e/selenium/spec/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def recursive_compact(thing)
$driver.get fixture "/nested-iframes.html"
res = with_js($axe_pre_43x) { run_axe }

expect(res.results.testEngine["version"]).to eq "4.0.3"
expect(res.results.testEngine["version"]).to eq "4.2.3"

label_vio = res.results.violations.find { |vio| vio.id == :label }
expect(label_vio).not_to be_nil
Expand Down Expand Up @@ -320,4 +320,46 @@ def recursive_compact(thing)
ft_inc = res.results.incomplete.find { |inc| inc.id == :'frame-tested' }
expect(ft_inc).to be_nil
end

describe "allowedOrigin" do
def get_allowed_origin
return $driver.execute_script("return axe._audit.allowedOrigins")
end

it "should not set when running runPartial and not legacy mode" do
$driver.get fixture "/index.html"
run_axe
allowed_origin = get_allowed_origin
expect(allowed_origin).to eq ["http://localhost:8000"]
expect(allowed_origin.length).to eq 1
end

it "should set when running runPartial and legacy mode" do
$driver.get fixture "/index.html"
with_legacy_mode { run_axe }
allowed_origin = get_allowed_origin
expect(allowed_origin).to eq ["http://localhost:8000"]
expect(allowed_origin.length).to eq 1
end

it "should not set when running legacy source and legacy mode" do
$driver.get fixture "/index.html"
with_legacy_mode {
with_js($axe_pre_43x) {
run_axe
}
}
allowed_origin = get_allowed_origin
expect(allowed_origin).to eq ["http://localhost:8000"]
expect(allowed_origin.length).to eq 1
end

it "should set when running legacy source and not legacy mode" do
$driver.get fixture "/index.html"
with_js($axe_pre_43x) { run_axe }
allowed_origin = get_allowed_origin
expect(allowed_origin).to eq ["*"]
expect(allowed_origin.length).to eq 1
end
end
end
14 changes: 7 additions & 7 deletions packages/axe-core-api/lib/axe/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ def call_verbatim(callable)
callable.call @page
end

def self.has_run_partial?(page)
page.evaluate_script <<-JS
typeof window.axe.runPartial === 'function'
JS
end

private

def use_run_partial
has_run_partial? and not Axe::Configuration.instance.legacy_mode
Core.has_run_partial?(@page) and not Axe::Configuration.instance.legacy_mode
end

def load_axe_core(source)
Expand All @@ -40,12 +46,6 @@ def load_axe_core(source)
loader.call source
end

def has_run_partial?
@page.evaluate_script <<-JS
typeof window.axe.runPartial === 'function'
JS
end

def already_loaded?
@page.evaluate_script <<-JS
window.#{JS_NAME} &&
Expand Down
5 changes: 3 additions & 2 deletions packages/axe-core-api/lib/loader.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require_relative "./axe/configuration"
require_relative "./axe/core"
require_relative "./hooks"

module Common
Expand All @@ -25,8 +26,8 @@ def call(source, is_top_level = true)
private

def set_allowed_origins
allowed_origins = "<unsafe_all_origins>"
allowed_origins = "<same_origin>" if Axe::Configuration.instance.legacy_mode
allowed_origins = "<same_origin>"
allowed_origins = "<unsafe_all_origins>" if !Axe::Configuration.instance.legacy_mode && !Axe::Core::has_run_partial?(@page)
@page.execute_script "axe.configure({ allowedOrigins: ['#{allowed_origins}'] });"
end

Expand Down