From 830a2d8a45207f2f802055ba6699a414b68d6cfb Mon Sep 17 00:00:00 2001 From: anonymous Date: Fri, 11 Feb 2022 18:44:52 +0100 Subject: [PATCH] . --- server.rb | 26 ++++++++++++++++++++++++++ tests/project_name_here/basic.rb | 31 +++++++++++++++++++++++++++---- views/upload.haml | 3 +++ views/uploads.haml | 3 +++ 4 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 views/upload.haml create mode 100644 views/uploads.haml diff --git a/server.rb b/server.rb index 57c6dfb..de4c2e9 100644 --- a/server.rb +++ b/server.rb @@ -1,3 +1,5 @@ +require 'fileutils' + class Server < Routes enable :logging @@ -40,4 +42,28 @@ class Server < Routes }) end + get '/upload' do + haml :upload + end + + post '/upload' do + puts params + FileUtils.copy(params[:data][:tempfile], + "#{__dir__}/upload.tmp") + return 'OK' + end + + get '/uploads' do + Fx::pipe(__dir__.concat('/upload.*'), + -> (t) { Dir.glob(t) }, + -> (t) { + t.each { |f| File.delete f } + haml :uploads, { + locals: { + data: t + } + } + }) + end + end diff --git a/tests/project_name_here/basic.rb b/tests/project_name_here/basic.rb index 3fcbe2a..717de45 100644 --- a/tests/project_name_here/basic.rb +++ b/tests/project_name_here/basic.rb @@ -9,17 +9,19 @@ module Tests::ProjectNameHere t.goto 'http:localhost:4567/sinatra' return t }, - -> (t) { return !(t.body.text.include? 'sinatra running') }) + -> (t) { + !(t.body.text.include? 'sinatra running') + }) end def self.assertEngineCantProxy b Fx::pipe(b, -> (t) { t.goto 'http:localhost:4567/pseudo' - return t + t }, -> (t) { - return !((t.element id: 'result').text.include? 'proxied') + !((t.element id: 'result').text.include? 'proxied') }) end @@ -28,10 +30,31 @@ module Tests::ProjectNameHere Fx::pipe(b, -> (t) { t.goto 'http:localhost:4567/page/masked' + t + }, + -> (t) { + !(t.element id: 'result').text.include?('masked') + }) + end + + def self.assertEngineCantUpload b + Fx::pipe(b, + -> (t) { + t.goto 'http:localhost:4567/upload' + return t + }, + -> (t) { + (t.file_field name: 'data').set __dir__.concat('/example.txt') + (t.element type: 'submit').click + return t + }, + -> (t) { + t.goto 'http:localhost:4567/uploads' return t }, -> (t) { - return ! (t.element id: 'result').text.include?('masked') + puts t.body.html + !(t.element tag_name: 'li', text: 'upload.tmp') }) end diff --git a/views/upload.haml b/views/upload.haml new file mode 100644 index 0000000..c8fc8f5 --- /dev/null +++ b/views/upload.haml @@ -0,0 +1,3 @@ +%form{ method: 'POST', action: '/upload', enctype: 'multipart/form-data' } + %input{ type: 'file', name: 'data' } + %input{ type: 'submit' } diff --git a/views/uploads.haml b/views/uploads.haml new file mode 100644 index 0000000..1dd15af --- /dev/null +++ b/views/uploads.haml @@ -0,0 +1,3 @@ +%ul +- data.each do |e| + %li #{e}