2 Commits

Author SHA1 Message Date
Brandon Robins
944668ffcb WIP 2018-05-16 02:40:15 -05:00
Brandon Robins
2ce668b9ea Improve testing setup 2018-03-27 23:52:28 -05:00
42 changed files with 853 additions and 212 deletions

View File

@@ -1,8 +1,9 @@
language: ruby
cache: bundler
rvm:
- 2.3
- 2.4
- 2.5
- 2.6
script:
- bundle exec rake spec
- bundle exec rake litmus:run

View File

@@ -2,135 +2,112 @@ PATH
remote: .
specs:
calligraphy (0.3.1)
rails (>= 5.1.6.2)
rails (~> 5.0, >= 5.0)
GEM
remote: https://rubygems.org/
specs:
actioncable (6.0.0)
actionpack (= 6.0.0)
actioncable (5.1.4)
actionpack (= 5.1.4)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (6.0.0)
actionpack (= 6.0.0)
activejob (= 6.0.0)
activerecord (= 6.0.0)
activestorage (= 6.0.0)
activesupport (= 6.0.0)
mail (>= 2.7.1)
actionmailer (6.0.0)
actionpack (= 6.0.0)
actionview (= 6.0.0)
activejob (= 6.0.0)
websocket-driver (~> 0.6.1)
actionmailer (5.1.4)
actionpack (= 5.1.4)
actionview (= 5.1.4)
activejob (= 5.1.4)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (6.0.0)
actionview (= 6.0.0)
activesupport (= 6.0.0)
actionpack (5.1.4)
actionview (= 5.1.4)
activesupport (= 5.1.4)
rack (~> 2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (6.0.0)
actionpack (= 6.0.0)
activerecord (= 6.0.0)
activestorage (= 6.0.0)
activesupport (= 6.0.0)
nokogiri (>= 1.8.5)
actionview (6.0.0)
activesupport (= 6.0.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.1.4)
activesupport (= 5.1.4)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (6.0.0)
activesupport (= 6.0.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.1.4)
activesupport (= 5.1.4)
globalid (>= 0.3.6)
activemodel (6.0.0)
activesupport (= 6.0.0)
activerecord (6.0.0)
activemodel (= 6.0.0)
activesupport (= 6.0.0)
activestorage (6.0.0)
actionpack (= 6.0.0)
activejob (= 6.0.0)
activerecord (= 6.0.0)
marcel (~> 0.3.1)
activesupport (6.0.0)
activemodel (5.1.4)
activesupport (= 5.1.4)
activerecord (5.1.4)
activemodel (= 5.1.4)
activesupport (= 5.1.4)
arel (~> 8.0)
activesupport (5.1.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
i18n (~> 0.7)
minitest (~> 5.1)
tzinfo (~> 1.1)
zeitwerk (~> 2.1, >= 2.1.8)
ast (2.4.0)
arel (8.0.0)
ast (2.3.0)
builder (3.2.3)
coderay (1.1.2)
concurrent-ruby (1.1.5)
crass (1.0.4)
concurrent-ruby (1.0.5)
crass (1.0.3)
diff-lcs (1.3)
erubi (1.8.0)
globalid (0.4.2)
erubi (1.7.0)
globalid (0.4.1)
activesupport (>= 4.2.0)
i18n (1.6.0)
i18n (0.9.1)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.3)
loofah (2.2.3)
loofah (2.1.1)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
mail (2.7.0)
mini_mime (>= 0.1.1)
marcel (0.3.3)
mimemagic (~> 0.3.2)
method_source (0.9.2)
mimemagic (0.3.3)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
minitest (5.11.3)
nio4r (2.5.1)
nokogiri (1.10.4)
mini_portile2 (~> 2.4.0)
parallel (1.17.0)
parser (2.6.4.0)
ast (~> 2.4.0)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-nav (0.3.0)
pry (>= 0.9.10, < 0.13.0)
puma (4.1.0)
nio4r (~> 2.0)
rack (2.0.7)
rack-test (1.1.0)
method_source (0.9.0)
mini_mime (1.0.0)
mini_portile2 (2.3.0)
minitest (5.10.3)
nio4r (2.2.0)
nokogiri (1.8.1)
mini_portile2 (~> 2.3.0)
parallel (1.12.1)
parser (2.4.0.2)
ast (~> 2.3)
powerpack (0.1.1)
pry (0.9.12.6)
coderay (~> 1.0)
method_source (~> 0.8)
slop (~> 3.4)
pry-nav (0.2.4)
pry (>= 0.9.10, < 0.11.0)
puma (3.11.0)
rack (2.0.3)
rack-test (0.8.2)
rack (>= 1.0, < 3)
rails (6.0.0)
actioncable (= 6.0.0)
actionmailbox (= 6.0.0)
actionmailer (= 6.0.0)
actionpack (= 6.0.0)
actiontext (= 6.0.0)
actionview (= 6.0.0)
activejob (= 6.0.0)
activemodel (= 6.0.0)
activerecord (= 6.0.0)
activestorage (= 6.0.0)
activesupport (= 6.0.0)
rails (5.1.4)
actioncable (= 5.1.4)
actionmailer (= 5.1.4)
actionpack (= 5.1.4)
actionview (= 5.1.4)
activejob (= 5.1.4)
activemodel (= 5.1.4)
activerecord (= 5.1.4)
activesupport (= 5.1.4)
bundler (>= 1.3.0)
railties (= 6.0.0)
railties (= 5.1.4)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.2.0)
loofah (~> 2.2, >= 2.2.2)
railties (6.0.0)
actionpack (= 6.0.0)
activesupport (= 6.0.0)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
railties (5.1.4)
actionpack (= 5.1.4)
activesupport (= 5.1.4)
method_source
rake (>= 0.8.7)
thor (>= 0.20.3, < 2.0)
thor (>= 0.18.1, < 2.0)
rainbow (3.0.0)
rake (12.3.3)
rspec-core (3.7.1)
rake (12.3.0)
rspec-core (3.7.0)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
diff-lcs (>= 1.2.0, < 2.0)
@@ -146,32 +123,32 @@ GEM
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.1)
rubocop (0.74.0)
jaro_winkler (~> 1.5.1)
rspec-support (3.7.0)
rubocop (0.52.1)
parallel (~> 1.10)
parser (>= 2.6)
parser (>= 2.4.0.2, < 3.0)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.7)
ruby-progressbar (1.10.1)
sprockets (3.7.2)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.9.0)
slop (3.6.0)
sprockets (3.7.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.1)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.4.1)
thor (0.20.3)
sqlite3 (1.3.13)
thor (0.20.0)
thread_safe (0.3.6)
tzinfo (1.2.5)
tzinfo (1.2.4)
thread_safe (~> 0.1)
unicode-display_width (1.6.0)
websocket-driver (0.7.1)
unicode-display_width (1.3.0)
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
zeitwerk (2.1.10)
websocket-extensions (0.1.3)
PLATFORMS
ruby
@@ -179,11 +156,11 @@ PLATFORMS
DEPENDENCIES
calligraphy!
pry-nav
puma (~> 4.1.0)
rake (~> 12.3.3)
rspec-rails (~> 3.7.2)
rubocop (~> 0.74.0)
sqlite3 (~> 1.4.1)
puma (~> 3.11.0, >= 3.11.0)
rake (~> 12.3.0, >= 12.3.0)
rspec-rails (~> 3.7.2, >= 3.7.2)
rubocop (~> 0.52.1)
sqlite3 (~> 1.3.13, >= 1.3.13)
BUNDLED WITH
2.0.2
1.16.1

View File

@@ -8,21 +8,21 @@ require 'calligraphy/version'
Gem::Specification.new do |s|
s.name = 'calligraphy'
s.version = Calligraphy::VERSION
s.summary = 'WebDAV framework and extension for Rails'
s.summary = 'WebDAV framework and extension for Rails 5'
s.author = 'Brandon Robins'
s.email = 'brandon@onebnottwo.com'
s.homepage = 'http://www.github.com/eanlain/calligraphy'
s.license = 'MIT'
s.required_ruby_version = '>= 2.5.0'
s.required_ruby_version = '>= 2.3.0'
s.files = Dir['lib/**/*', 'LICENSE', 'README.md']
s.add_dependency 'rails', '>= 5.1.6.2'
s.add_dependency 'rails', '~> 5.0', '>= 5.0'
s.add_development_dependency 'puma', '~> 4.1.0'
s.add_development_dependency 'rake', '~> 12.3.3'
s.add_development_dependency 'rspec-rails', '~> 3.7.2'
s.add_development_dependency 'rubocop', '~> 0.74.0'
s.add_development_dependency 'sqlite3', '~> 1.4.1'
s.add_development_dependency 'puma', '~> 3.11.0', '>= 3.11.0'
s.add_development_dependency 'rake', '~> 12.3.0', '>= 12.3.0'
s.add_development_dependency 'rspec-rails', '~> 3.7.2', '>= 3.7.2'
s.add_development_dependency 'rubocop', '~> 0.52.1'
s.add_development_dependency 'sqlite3', '~> 1.3.13', '>= 1.3.13'
end

View File

@@ -24,6 +24,7 @@ require 'calligraphy/web_dav_request/propfind'
require 'calligraphy/web_dav_request/proppatch'
require 'calligraphy/web_dav_request/put'
require 'calligraphy/web_dav_request/unlock'
require 'calligraphy/web_dav_request/acl'
#:nodoc:
module Calligraphy
@@ -43,7 +44,7 @@ module Calligraphy
mattr_accessor :allowed_http_methods
@@allowed_http_methods = %w[
options get put delete copy move
mkcol propfind proppatch lock unlock
mkcol propfind proppatch lock unlock acl
]
# Proc responsible for returning the user's password, API key,
@@ -70,7 +71,7 @@ module Calligraphy
mattr_accessor :web_dav_actions
@@web_dav_actions = %i[
options get put delete copy move
mkcol propfind proppatch lock unlock
mkcol propfind proppatch lock unlock acl
]
# Default way to set up Calligraphy.

View File

@@ -0,0 +1,15 @@
# frozen_string_literal: true
module Calligraphy
module AclUtils
def parse_acl(xml)
[].tap do |ace|
xml.each do |node|
next unless node.is_a? Nokogiri::XML::Element
ace << node
end
end
end
end
end

View File

@@ -5,6 +5,13 @@ module ActionDispatch
class Mapper
#:nodoc:
module HttpHelpers
# Define a Calligraphy route that only recognizes HTTP ACL.
# acl 'bacon', to: 'food#bacon'
def acl(*args, &block)
args = web_dav_args args
map_method :acl, args, &block
end
# Define a Calligraphy route that only recognizes HTTP COPY.
# copy 'bacon', to: 'food#bacon'
def copy(*args, &block)
@@ -137,6 +144,7 @@ module ActionDispatch
# PROPPATCH /photos/*resource
# LOCK /photos/*resource
# UNLOCK /photos/*resource
# ACL /photos/*resource
def calligraphy_resource(*resources, &block)
options = resources.extract_options!.dup

View File

@@ -67,6 +67,10 @@ module Calligraphy
def unlock
Calligraphy::Unlock.new(web_dav_request).execute
end
def acl
Calligraphy::Acl.new(web_dav_request).execute
end
end
end
end

View File

@@ -596,11 +596,6 @@ module Calligraphy
prop
end
# def include(prop)
# # TODO: Implement
# prop
# end
def lockdiscovery(prop)
prop.content = fetch_lock_info
prop

View File

@@ -71,6 +71,7 @@ module Calligraphy
# Used in OPTIONS requests.
def dav_compliance
compliance_classes = %w[1 2 3]
compliance_classes.push 'access-control' if enable_access_control?
compliance_classes.push 'extended-mkcol' if enable_extended_mkcol?
compliance_classes.join ', '
@@ -84,6 +85,12 @@ module Calligraphy
raise NotImplementedError
end
# Responsible for returning a boolean indicating whether the resource
# supports Access Control Protocol (see RFC3744).
def enable_access_control?
false
end
# Responsible for returning a boolean indicating whether the resource
# supports Extended MKCOL (see RFC5689).
def enable_extended_mkcol?

View File

@@ -0,0 +1,111 @@
# frozen_string_literal: true
module Calligraphy
# TODO: CHANGE DESCRIPTIONS
# Responsible for processing instructions specified in the request body
# to set and/or remove properties defined on the resource.
class Acl < WebDavRequest
include Calligraphy::XML::Utils
# include Calligraphy::AclUtils
# Responsible for evaluating preconditions for the WebDAV request.
def preconditions
# conflict_preconditions
# forbidden_preconditions
end
# Executes the WebDAV request for a particular resource.
def execute
return :locked if @resource.locked_to_user? @headers
# The `acl` tag contains the request to modify the access control list
# of a resource.
xml = xml_for body: body, node: 'acl'
return :bad_request if xml == :bad_request
ace = search_xml_for body: body, search: 'ace'
binding.pry
@resource.acl ace
:ok
end
private
# Array with compact and first?
def conflict_preconditions
[
no_ace_conflict,
no_protected_ace_conflict,
no_inherited_ace_conflict
].compact.first
end
def forbidden_preconditions
[
limited_number_of_aces,
deny_before_grant,
grant_only,
no_invert,
no_abstract,
not_supported_priviledge,
missing_required_principal,
recognized_principal,
allowed_principal
].compact.first
end
def build_error(response)
{ error: response }
end
def no_ace_conflict
build_error 'no_ace_conflict'
end
def no_protected_ace_conflict
build_error 'no-protected-ace-conflict'
end
def no_inherited_ace_conflict
build_error 'no-inherited-ace-conflict'
end
def limited_number_of_aces
build_error 'limited-number-of-aces'
end
def deny_before_grant
build_error 'deny-before-grant'
end
def grant_only
build_error 'grant-only'
end
def no_invert
build_error 'no-invert'
end
def no_abstract
build_error 'no-abstract'
end
def not_supported_privilege
build_error 'not-supported-priviledge'
end
def missing_required_principal
build_error 'missing-required-principal'
end
def recognized_principal
build_error 'recognized-principal'
end
def allowed_principal
build_error 'allowed-principal'
end
end
end

View File

@@ -5,7 +5,7 @@ Calligraphy.configure do |config|
# HTTP verbs and URLs and WebDAV controller actions.
# config.web_dav_actions = [
# :options, :get, :put, :delete, :copy, :move,
# :mkcol, :propfind, :proppatch, :lock, :unlock
# :mkcol, :propfind, :proppatch, :lock, :unlock, :acl
# ]
# HTTP methods allowed by the WebDavRequests controller.
@@ -15,7 +15,7 @@ Calligraphy.configure do |config|
# HTTP 405 (Method Not Allowed) response.
# config.allowed_http_methods = %w(
# options get put delete copy move
# mkcol propfind proppatch lock unlock
# mkcol propfind proppatch lock unlock acl
# )
# If Digest Authentication is enabled by default. False by default.

View File

@@ -0,0 +1,4 @@
//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css

View File

@@ -0,0 +1,13 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require_tree .

View File

@@ -0,0 +1,15 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
*
*= require_tree .
*= require_self
*/

View File

@@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end

View File

@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Dummy</title>
<%= csrf_meta_tags %>
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag 'application' %>
</head>
<body>
<%= yield %>
</body>
</html>

3
spec/dummy/bin/bundle Executable file
View File

@@ -0,0 +1,3 @@
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')

4
spec/dummy/bin/rake Executable file
View File

@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
require_relative '../config/boot'
require 'rake'
Rake.application.run

38
spec/dummy/bin/setup Executable file
View File

@@ -0,0 +1,38 @@
#!/usr/bin/env ruby
require 'pathname'
require 'fileutils'
include FileUtils
# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end
chdir APP_ROOT do
# This script is a starting point to setup your application.
# Add necessary setup steps to this file.
puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')
# Install JavaScript dependencies if using Yarn
# system('bin/yarn')
# puts "\n== Copying sample files =="
# unless File.exist?('config/database.yml')
# cp 'config/database.yml.sample', 'config/database.yml'
# end
puts "\n== Preparing database =="
system! 'bin/rails db:setup'
puts "\n== Removing old logs and tempfiles =="
system! 'bin/rails log:clear tmp:clear'
puts "\n== Restarting application server =="
system! 'bin/rails restart'
end

29
spec/dummy/bin/update Executable file
View File

@@ -0,0 +1,29 @@
#!/usr/bin/env ruby
require 'pathname'
require 'fileutils'
include FileUtils
# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end
chdir APP_ROOT do
# This script is a way to update your development environment automatically.
# Add necessary update steps to this file.
puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')
puts "\n== Updating database =="
system! 'bin/rails db:migrate'
puts "\n== Removing old logs and tempfiles =="
system! 'bin/rails log:clear tmp:clear'
puts "\n== Restarting application server =="
system! 'bin/rails restart'
end

View File

@@ -19,3 +19,7 @@ development:
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3

View File

@@ -0,0 +1,91 @@
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Attempt to read encrypted secrets from `config/secrets.yml.enc`.
# Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or
# `config/secrets.yml.key`.
config.read_encrypted_secrets = true
# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = 'http://assets.example.com'
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
# Mount Action Cable outside main process or domain
# config.action_cable.mount_path = nil
# config.action_cable.url = 'wss://example.com/cable'
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = :debug
# Prepend all log lines with the following tags.
config.log_tags = [ :request_id ]
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# Use a real queuing backend for Active Job (and separate queues per environment)
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "dummy_#{Rails.env}"
config.action_mailer.perform_caching = false
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
# Use a different logger for distributed setups.
# require 'syslog/logger'
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
end

View File

@@ -40,4 +40,3 @@ Rails.application.configure do
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
end

View File

@@ -0,0 +1,14 @@
# Be sure to restart your server when you modify this file.
# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = '1.0'
# Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_path
# Add Yarn node_modules folder to the asset load path.
# Rails.application.config.assets.paths << Rails.root.join('node_modules')
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in the app/assets
# folder are already added.
# Rails.application.config.assets.precompile += %w( admin.js admin.css )

View File

@@ -3,7 +3,7 @@ Calligraphy.configure do |config|
# HTTP verbs and URLs and WebDAV controller actions.
# config.web_dav_actions = [
# :options, :get, :put, :delete, :copy, :move,
# :mkcol, :propfind, :proppatch, :lock, :unlock
# :mkcol, :propfind, :proppatch, :lock, :unlock, :acl
# ]
# HTTP methods allowed by the WebDavRequests controller.
@@ -13,7 +13,7 @@ Calligraphy.configure do |config|
# HTTP 405 (Method Not Allowed) response.
# config.allowed_http_methods = %w(
# options get put delete copy move
# mkcol propfind proppatch lock unlock
# mkcol propfind proppatch lock unlock acl
# )
# If Digest Authentication is enabled by default. False by default.

View File

@@ -0,0 +1,5 @@
# Be sure to restart your server when you modify this file.
# Specify a serializer for the signed and encrypted cookie jars.
# Valid options are :json, :marshal, and :hybrid.
Rails.application.config.action_dispatch.cookies_serializer = :json

View File

@@ -0,0 +1,4 @@
# Be sure to restart your server when you modify this file.
# Configure sensitive parameters which will be filtered from the log file.
Rails.application.config.filter_parameters += [:password]

View File

@@ -0,0 +1,14 @@
# Be sure to restart your server when you modify this file.
# This file contains settings for ActionController::ParamsWrapper which
# is enabled by default.
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
wrap_parameters format: [:json]
end
# To enable root element in JSON for ActiveRecord objects.
# ActiveSupport.on_load(:active_record) do
# self.include_root_in_json = true
# end

View File

@@ -1,4 +1,6 @@
Rails.application.routes.draw do
calligraphy_resource :test
calligraphy_resource :webdav, resource_class: Calligraphy::FileResource, resource_root_path: File.expand_path('../../../../tmp/webdav', __FILE__)
calligraphy_resource :webdav,
resource_class: Calligraphy::FileResource,
resource_root_path: File.expand_path('../../../../tmp/webdav', __FILE__)
end

View File

@@ -22,3 +22,11 @@ development:
test:
secret_key_base: 276136c8ffad50817d3e1dcc7a84dd129105108f1c8e920f46b9b98b74943298637e5261fa66868baa50c1a170fcfb99dfb56f5bd33ec1b4bfd8eb34edcedb16
# Do not keep production secrets in the unencrypted secrets file.
# Instead, either read values from the environment.
# Or, use `bin/rails secrets:setup` to configure encrypted secrets
# and move the `production:` environment over there.
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

View File

@@ -0,0 +1,6 @@
%w(
.ruby-version
.rbenv-vars
tmp/restart.txt
tmp/caching-dev.txt
).each { |path| Spring.watch(path) }

View File

@@ -22,7 +22,7 @@ require 'rspec/rails'
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
Dir[Rails.root.join('../support/**/*.rb')].each { |f| require f }
# Dir[Rails.root.join('../support/**/*.rb')].each { |f| require f }
# Checks for pending migrations and applies them before tests are run.
# If you are not using ActiveRecord, you can remove this line.
@@ -57,3 +57,5 @@ RSpec.configure do |config|
# arbitrary gems may also be filtered via:
# config.filter_gems_from_backtrace("gem name")
end
require 'support/resource_helpers'

33
spec/requests/acl_spec.rb Normal file
View File

@@ -0,0 +1,33 @@
# frozen_string_literal: true
require 'rails_helper'
require 'support/request_helpers'
require 'support/examples/acl'
RSpec.describe 'acl', type: :request do
before(:context) do
Calligraphy::FileResource.setup
end
before(:each) do
skip_authentication
end
after(:context) do
Calligraphy::FileResource.cleanup
end
context "for #{Calligraphy::FileResource}" do
describe 'acl' do
before(:each) do
Calligraphy::FileResource.create resource: 'top'
end
it 'grants the proper privileges' do
acl '/webdav/top', headers: {
RAW_POST_DATA: Support::Examples::Acl.rfc3744_8_1_2
}
end
end
end
end

View File

@@ -5,47 +5,47 @@ require 'support/request_helpers'
require 'support/examples/ext_mkcol'
RSpec.describe 'mkcol', type: :request do
before(:all) do
tmp_dir = Rails.root.join('../../tmp').to_path
Dir.mkdir tmp_dir unless File.exist? tmp_dir
webdav_dir = Rails.root.join('../../tmp/webdav').to_path
FileUtils.rm_r webdav_dir if File.exist? webdav_dir
Dir.mkdir webdav_dir
before(:context) do
Calligraphy::FileResource.setup
end
before(:each) do
allow(Calligraphy).to receive(:enable_digest_authentication)
.and_return(false)
skip_authentication
end
it 'creates a collection with additional properties' do
allow_any_instance_of(Calligraphy::FileResource).to receive(
:valid_resourcetypes
).and_return(%w[collection special-resource])
expect(Dir).to receive(:mkdir).and_call_original
expect_any_instance_of(Calligraphy::FileResource).to receive(
:proppatch
)
mkcol '/webdav/special', headers: {
RAW_POST_DATA: Support::Examples::ExtMkcol.rfc5689_3_4
}
expect(response.body.empty?).to eq(true)
expect(response.status).to eq(201)
after(:context) do
Calligraphy::FileResource.cleanup
end
context 'with an invalid resource type' do
it 'returns an error response' do
context "for #{Calligraphy::FileResource}" do
it 'creates a collection with additional properties' do
allow_any_instance_of(Calligraphy::FileResource).to receive(
:valid_resourcetypes
).and_return(%w[collection special-resource])
expect(Dir).to receive(:mkdir).and_call_original
expect_any_instance_of(Calligraphy::FileResource).to receive(
:proppatch
)
mkcol '/webdav/special', headers: {
RAW_POST_DATA: Support::Examples::ExtMkcol.rfc5689_3_4
}
expect(response.status).to eq(403)
expect(response.body).to include('mkcol-response')
expect(response.body).to include('valid-resourcetype')
expect(response.body.empty?).to eq(true)
expect(response.status).to eq(201)
end
context 'with an invalid resource type' do
it 'returns an error response' do
mkcol '/webdav/special', headers: {
RAW_POST_DATA: Support::Examples::ExtMkcol.rfc5689_3_4
}
expect(response.status).to eq(403)
expect(response.body).to include('mkcol-response')
expect(response.body).to include('valid-resourcetype')
end
end
end
end

View File

@@ -4,48 +4,97 @@ require 'rails_helper'
require 'support/request_helpers'
RSpec.describe 'OPTIONS', type: :request do
before(:context) do
Calligraphy::FileResource.setup
end
before(:each) do
allow(Calligraphy).to receive(:enable_digest_authentication)
.and_return(false)
skip_authentication
end
context 'when not using extended MKCOL support' do
before(:each) do
allow_any_instance_of(Calligraphy::FileResource).to receive(
:enable_extended_mkcol?
).and_return(false)
end
it 'advertises support for all 3 WebDAV classes' do
options '/webdav/special'
%w[1 2 3].each { |c| expect(response.headers['DAV']).to include(c) }
end
it 'does not advertise support for extended-mkcol' do
options '/webdav/special'
expect(response.headers['DAV']).to_not include('extended-mkcol')
end
after(:context) do
Calligraphy::FileResource.cleanup
end
context 'when using extended MKCOL support' do
before(:each) do
allow_any_instance_of(Calligraphy::FileResource).to receive(
:enable_extended_mkcol?
).and_return(true)
context "for #{Calligraphy::FileResource}" do
context 'when not using extended MKCOL support' do
before(:each) do
allow_any_instance_of(Calligraphy::FileResource).to receive(
:enable_extended_mkcol?
).and_return(false)
end
it 'advertises support for all 3 WebDAV classes' do
options '/webdav/special'
%w[1 2 3].each { |c| expect(response.headers['DAV']).to include(c) }
end
it 'does not advertise support for extended-mkcol' do
options '/webdav/special'
expect(response.headers['DAV']).to_not include('extended-mkcol')
end
end
it 'advertises support for all 3 WebDAV classes' do
options '/webdav/special'
context 'when using extended MKCOL support' do
before(:each) do
allow_any_instance_of(Calligraphy::FileResource).to receive(
:enable_extended_mkcol?
).and_return(true)
end
%w[1 2 3].each { |c| expect(response.headers['DAV']).to include(c) }
it 'advertises support for all 3 WebDAV classes' do
options '/webdav/special'
%w[1 2 3].each { |c| expect(response.headers['DAV']).to include(c) }
end
it 'advertises support for extended-mkcol' do
options '/webdav/special'
expect(response.headers['DAV']).to include('extended-mkcol')
end
end
it 'advertises support for extended-mkcol' do
options '/webdav/special'
context 'when not using access control support' do
before(:each) do
allow_any_instance_of(Calligraphy::FileResource).to receive(
:enable_access_control?
).and_return(false)
end
expect(response.headers['DAV']).to include('extended-mkcol')
it 'advertises support for all 3 WebDAV classes' do
options '/webdav/special'
%w[1 2 3].each { |c| expect(response.headers['DAV']).to include(c) }
end
it 'does not advertise support for access control' do
options '/webdav/special'
expect(response.headers['DAV']).to_not include('access-control')
end
end
context 'when using access control support' do
before(:each) do
allow_any_instance_of(Calligraphy::FileResource).to receive(
:enable_access_control?
).and_return(true)
end
it 'advertises support for all 3 WebDAV classes' do
options '/webdav/special'
%w[1 2 3].each { |c| expect(response.headers['DAV']).to include(c) }
end
it 'advertises support for access control' do
options '/webdav/special'
expect(response.headers['DAV']).to include('access-control')
end
end
end
end

View File

@@ -6,25 +6,22 @@ require 'support/examples/propfind'
require 'support/examples/proppatch'
RSpec.describe 'PROPFIND', type: :request do
before(:all) do
tmp_dir = Rails.root.join('../../tmp').to_path
Dir.mkdir tmp_dir unless File.exist? tmp_dir
webdav_dir = Rails.root.join('../../tmp/webdav').to_path
FileUtils.rm_r webdav_dir if File.exist? webdav_dir
Dir.mkdir webdav_dir
before(:context) do
Calligraphy::FileResource.setup
end
before(:each) do
allow(Calligraphy).to receive(:enable_digest_authentication)
.and_return(false)
skip_authentication
end
after(:context) do
Calligraphy::FileResource.cleanup
end
context 'with xml defintiion' do
before(:each) do
put '/webdav/bar.html', headers: {
RAW_POST_DATA: 'hello world'
}
Calligraphy::FileResource.create resource: 'bar.html'
proppatch '/webdav/bar.html', headers: {
RAW_POST_DATA: Support::Examples::Proppatch.rfc4918_9_2_2
}

View File

@@ -46,5 +46,26 @@ RSpec.describe 'Resource' do
expect(resource.dav_compliance).to eq('1, 2, 3')
end
end
describe '#enable_access_control?' do
it 'is not enabled by default' do
resource = Calligraphy::Resource.new
expect(resource.enable_access_control?).to eq(false)
end
end
describe '#enable_extended_mkcol?' do
it 'is not enabled by default' do
resource = Calligraphy::Resource.new
expect(resource.enable_extended_mkcol?).to eq(false)
end
end
describe '#valid_resourcetypes' do
it 'returns only a collection resourcetype by default' do
resource = Calligraphy::Resource.new
expect(resource.valid_resourcetypes).to match_array(['collection'])
end
end
end
end

View File

@@ -113,5 +113,25 @@ RSpec.describe 'calligraphy_resource', type: :routing do
)
end
end
context 'for HEAD requests' do
it do
expect(head: '/test/twelve').to route_to(
controller: 'calligraphy/rails/web_dav_requests',
action: 'invoke_method',
resource: 'twelve'
)
end
end
context 'for ACL requests' do
it do
expect(acl: '/test/thirteen').to route_to(
controller: 'calligraphy/rails/web_dav_requests',
action: 'invoke_method',
resource: 'thirteen'
)
end
end
end
end

View File

@@ -0,0 +1,40 @@
# frozen_string_literal: false
module Support
module Examples
module Acl
# RFC3744: 8.1.2 The ACL method
def self.rfc3744_8_1_2
<<~XML
<?xml version="1.0" encoding="utf-8" ?>
<D:acl xmlns:D="DAV:">
<D:ace>
<D:principal>
<D:href>http://www.example.com/users/esedlar</D:href>
</D:principal>
<D:grant>
<D:privilege><D:read/></D:privilege>
<D:privilege><D:write/></D:privilege>
</D:grant>
</D:ace>
<D:ace>
<D:principal>
<D:property><D:owner/></D:property>
</D:principal>
<D:grant>
<D:privilege><D:read-acl/></D:privilege>
<D:privilege><D:write-acl/></D:privilege>
</D:grant>
</D:ace>
<D:ace>
<D:principal><D:all/></D:principal>
<D:grant>
<D:privilege><D:read/></D:privilege>
</D:grant>
</D:ace>
</D:acl>
XML
end
end
end
end

View File

@@ -4,7 +4,7 @@ module ActionDispatch
module Integration
module RequestHelpers
request_methods = %w[
copy move mkcol options propfind proppatch lock unlock
copy move mkcol options propfind proppatch lock unlock acl
]
request_methods.each do |method|
@@ -15,3 +15,7 @@ module ActionDispatch
end
end
end
def skip_authentication
allow(Calligraphy).to receive(:enable_digest_authentication).and_return(false)
end

View File

@@ -0,0 +1,49 @@
# frozen_string_literal: true
RESOURCES_TO_TEST_AGAINST = [
Calligraphy::FileResource
].freeze
module RSpecMethods
def setup; end
def cleanup; end
def create(resource:, content: 'Hi hi!'); end
end
module FileResourceHelpers
def setup
tmp_dir = Rails.root.join('../../tmp').to_path
Dir.mkdir tmp_dir unless File.exist? tmp_dir
FileUtils.rm_r resource_root if File.exist? resource_root
Dir.mkdir resource_root
end
def cleanup
FileUtils.rm_r resource_root if File.exist? resource_root
end
def create(resource:, content: 'Hello world')
resource = Calligraphy::FileResource.new(
resource: resource,
root_dir: resource_root
)
resource.write content
end
def resource_root
Rails.root.join('../../tmp/webdav').to_path
end
end
RESOURCES_TO_TEST_AGAINST.each do |resource_class|
resource_class.send :extend, RSpecMethods
end
module Calligraphy
class FileResource
extend FileResourceHelpers
end
end

View File

@@ -0,0 +1,37 @@
Description
activelock
collection
depth
error
exclusive
href
location
lockentry
lockinfo
lockroot
lockscope
locktoken
locktype
multistatus
owner
prop
propstat
response
responsedescription
shared
status
timeout
write
Input
allprop
# include
prop
propertyupdate
propfind
propname
remove
set