add ui jwt workflow that includes high contrast

define a new workflow inteded to be used by any service that needs to
render a ui. this workflow includes state indicating if high contrast
styles should be used.

refs CNVS-31909, closes CNVS-31983

test plan:
- enable high contrast
- make sure rcs is enabled
- go to view with rce sidebar
- get the jwt from Authoriation header of requests to rcs
  - don't inclued "Bearer "
- open the canvas console, run:
  Canvas::Security.decrypt_services_jwt(
    Canvas::Security.base64_decode('<token here>')
  )
- make suer the token inclues use_high_contrast: true
- disable high contrast
- repeat, but  use_high_contrast should be false in the token

Change-Id: I8752ad534928081d2e4b8e8d748f8dd9897222a2
Reviewed-on: https://gerrit.instructure.com/90452
Tested-by: Jenkins
Reviewed-by: John Corrigan <jcorrigan@instructure.com>
QA-Review: Jeremy Putnam <jeremyp@instructure.com>
Product-Review: Brent Burgoyne <bburgoyne@instructure.com>
This commit is contained in:
Brent Burgoyne 2016-09-15 10:05:55 -06:00
parent 171c74b06d
commit fe4ac3e8eb
4 changed files with 26 additions and 2 deletions

View File

@ -42,5 +42,11 @@ module Canvas
) || false
}
end
register(:ui) do |_, user|
{
use_high_contrast: user.try(:prefers_high_contrast?)
}
end
end
end

View File

@ -11,7 +11,7 @@ module Services
user,
context: context,
real_user: real_user,
workflows: [:rich_content]
workflows: [:rich_content, :ui]
)
end

View File

@ -69,6 +69,24 @@ module Canvas
expect(state[:usage_rights_required]).to be true
end
end
describe ':ui' do
before(:each) do
@u.stubs(:prefers_high_contrast?)
end
it 'sets use_high_contrast to true' do
@u.expects(:prefers_high_contrast?).returns(true)
state = JWTWorkflow.state_for([:ui], @c, @u)
expect(state[:use_high_contrast]).to be true
end
it 'sets use_high_contrast to false' do
@u.expects(:prefers_high_contrast?).returns(false)
state = JWTWorkflow.state_for([:ui], @c, @u)
expect(state[:use_high_contrast]).to be false
end
end
end
end
end

View File

@ -51,7 +51,7 @@ module Services
ctx = stub("ctx", grants_any_right?: true)
jwt = stub("jwt")
Canvas::Security::ServicesJwt.stubs(:for_user).with(domain, user, all_of(
has_entry(workflows: [:rich_content]),
has_entry(workflows: [:rich_content, :ui]),
has_entry(context: ctx)
)).returns(jwt)
env = described_class.env_for(root_account, user: user, domain: domain, context: ctx)