|
41 | 41 | end |
42 | 42 | end |
43 | 43 |
|
| 44 | + context "should support User as a context" do |
| 45 | + before(:each) do |
| 46 | + user_with_pseudonym |
| 47 | + login_as |
| 48 | + @me = @user |
| 49 | + @att = @me.attachments.create(:uploaded_data => stub_png_data('my-pic.png')) |
| 50 | + end |
| 51 | + |
| 52 | + it "with safefiles" do |
| 53 | + HostUrl.stub!(:file_host).and_return('files-test.host') |
| 54 | + get "http://test.host/users/#{@me.id}/files/#{@att.id}/download" |
| 55 | + response.should be_redirect |
| 56 | + uri = URI.parse response['Location'] |
| 57 | + qs = Rack::Utils.parse_nested_query(uri.query) |
| 58 | + uri.host.should == 'files-test.host' |
| 59 | + # redirects to a relative url, since relative files are available in user context |
| 60 | + uri.path.should == "/users/#{@me.id}/files/#{@att.id}/my%20files/unfiled/my-pic.png" |
| 61 | + @me.valid_access_verifier?(qs['ts'], qs['sf_verifier']).should be_true |
| 62 | + location = response['Location'] |
| 63 | + reset! |
| 64 | + |
| 65 | + get location |
| 66 | + response.should be_success |
| 67 | + response.content_type.should == 'image/png' |
| 68 | + # ensure that the user wasn't logged in by the normal means |
| 69 | + controller.instance_variable_get(:@current_user).should be_nil |
| 70 | + end |
| 71 | + |
| 72 | + it "without safefiles" do |
| 73 | + HostUrl.stub!(:file_host).and_return('test.host') |
| 74 | + get "http://test.host/users/#{@me.id}/files/#{@att.id}/download" |
| 75 | + response.should be_success |
| 76 | + response.content_type.should == 'image/png' |
| 77 | + response['Pragma'].should be_nil |
| 78 | + response['Cache-Control'].should_not match(/no-cache/) |
| 79 | + end |
| 80 | + |
| 81 | + context "with inlineable html files" do |
| 82 | + before do |
| 83 | + @att = @me.attachments.create(:uploaded_data => stub_file_data("ohai.html", "<html><body>ohai</body></html>", "text/html")) |
| 84 | + end |
| 85 | + |
| 86 | + it "with safefiles" do |
| 87 | + HostUrl.stub!(:file_host).and_return('files-test.host') |
| 88 | + get "http://test.host/users/#{@me.id}/files/#{@att.id}/download", :wrap => '1' |
| 89 | + response.should be_redirect |
| 90 | + uri = URI.parse response['Location'] |
| 91 | + qs = Rack::Utils.parse_nested_query(uri.query) |
| 92 | + uri.host.should == 'test.host' |
| 93 | + uri.path.should == "/users/#{@me.id}/files/#{@att.id}" |
| 94 | + location = response['Location'] |
| 95 | + |
| 96 | + get location |
| 97 | + # the response will be on the main domain, with an iframe pointing to the files domain and the actual uploaded html file |
| 98 | + response.should be_success |
| 99 | + response.content_type.should == 'text/html' |
| 100 | + doc = Nokogiri::HTML::DocumentFragment.parse(response.body) |
| 101 | + doc.at_css('iframe#file_content')['src'].should =~ %r{^http://files-test.host/users/#{@me.id}/files/#{@att.id}/my%20files/unfiled/ohai.html} |
| 102 | + end |
| 103 | + |
| 104 | + it "without safefiles" do |
| 105 | + HostUrl.stub!(:file_host).and_return('test.host') |
| 106 | + get "http://test.host/users/#{@me.id}/files/#{@att.id}/download", :wrap => '1' |
| 107 | + response.should be_redirect |
| 108 | + location = response['Location'] |
| 109 | + URI.parse(location).path.should == "/users/#{@me.id}/files/#{@att.id}" |
| 110 | + get location |
| 111 | + response.content_type.should == 'text/html' |
| 112 | + doc = Nokogiri::HTML::DocumentFragment.parse(response.body) |
| 113 | + doc.at_css('iframe#file_content')['src'].should =~ %r{^http://test.host/users/#{@me.id}/files/#{@att.id}/my%20files/unfiled/ohai.html} |
| 114 | + end |
| 115 | + |
| 116 | + end |
| 117 | + end |
| 118 | + |
44 | 119 | it "should use relative urls for safefiles in course context" do |
45 | 120 | course_with_teacher(:active_all => true, :user => user_with_pseudonym) |
46 | 121 | login_as |
|
0 commit comments