add validations to MediaTrack
test plan: passing incorrectly formatted data in the `kind` and `locale` parameters to POST /media_objects/:media_object_id/media_tracks should result in an error refs LA-172 flag=none Change-Id: Ibe9e13022dc858b15c0341a058a1cf9c9d528d39 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/219869 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Tested-by: Jenkins QA-Review: Anju Reddy <areddy@instructure.com> Reviewed-by: Mysti Lilla <mysti@instructure.com> Product-Review: Jeremy Stanley <jeremy@instructure.com>
This commit is contained in:
parent
f2a1725e1d
commit
47886e0320
|
@ -20,6 +20,8 @@ class MediaTrack < ActiveRecord::Base
|
|||
belongs_to :media_object, :touch => true
|
||||
before_save :convert_srt_to_wvtt
|
||||
validates :media_object_id, presence: true
|
||||
validates :kind, inclusion: { in: %w(subtitles captions descriptions chapters metadata) }
|
||||
validates :locale, format: { with: /\A[A-Za-z\-]+\z/ }
|
||||
validates :content, presence: true
|
||||
|
||||
RE_LOOKS_LIKE_TTML = /<tt\s+xml/i
|
||||
|
|
|
@ -53,6 +53,16 @@ describe MediaTracksController do
|
|||
post 'create', params: {:media_object_id => @mo.media_id, :kind => 'subtitles', :locale => 'en', :content => example_ttml_susceptible_to_xss}
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
end
|
||||
|
||||
it "should validate :kind" do
|
||||
post 'create', params: {:media_object_id => @mo.media_id, :kind => 'unkind', :locale => 'en', :content => '1'}
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
end
|
||||
|
||||
it "should validate :locale" do
|
||||
post 'create', params: {:media_object_id => @mo.media_id, :kind => 'subtitles', :locale => '<img src="lolcats.gif">', :content => '1'}
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#show" do
|
||||
|
|
Loading…
Reference in New Issue