diff --git a/db/environment.rb b/db/environment.rb index 0f57158..79b0d5f 100644 --- a/db/environment.rb +++ b/db/environment.rb @@ -4,24 +4,24 @@ require 'thread/local' module VMail + case Variant.default + when :production + MAIL_ROOT = "/srv/mail" + DOMAIN = 'https://mail.oriontransfer.net' + CREDENTIALS = {username: 'http', database: 'vmail'} + when :development + MAIL_ROOT = "db/mail" + DOMAIN = 'https://localhost' + CREDENTIALS = {username: 'test', password: 'test', database: 'vmail_development'} + when :testing + MAIL_ROOT = "db/mail" + DOMAIN = 'https://localhost' + CREDENTIALS = {username: 'test', password: 'test', database: 'test'} + end + module Database extend Thread::Local - case Variant.default - when :production - MAIL_ROOT = "/srv/mail" - DOMAIN = 'https://mail.oriontransfer.net' - CREDENTIALS = {username: 'http', database: 'vmail'} - when :development - MAIL_ROOT = "db/mail" - DOMAIN = 'https://localhost' - CREDENTIALS = {username: 'test', password: 'test', database: 'vmail_development'} - when :testing - MAIL_ROOT = "db/mail" - DOMAIN = 'https://localhost' - CREDENTIALS = {username: 'test', password: 'test', database: 'test', unix_socket: "/opt/local/var/run/mariadb-10.11/mysqld.sock"} - end - def self.local DB::Client.new(DB::MariaDB::Adapter.new(**CREDENTIALS)) end diff --git a/fixtures/website_context.rb b/fixtures/website_context.rb index c0fc06e..c46ba81 100644 --- a/fixtures/website_context.rb +++ b/fixtures/website_context.rb @@ -20,8 +20,8 @@ def app end def middleware - Falcon::Middleware::Verbose.new( + # Falcon::Middleware::Verbose.new( Protocol::Rack::Adapter.new(app) - ) + # ) end end diff --git a/gems.locked b/gems.locked index 3597db6..98fb977 100644 --- a/gems.locked +++ b/gems.locked @@ -1,18 +1,3 @@ -GIT - remote: https://github.com/socketry/db-migrate - revision: c0d46eb1934aa056a024e6a7677bc4afea3a172c - specs: - db-migrate (0.1.0) - db - migrate (~> 0.3) - -GIT - remote: https://github.com/socketry/db-model - revision: c369a05d33086bed21964dd70402d378fbf55e53 - specs: - db-model (0.4.0) - db (~> 0.10.0) - GEM remote: https://rubygems.org/ specs: @@ -26,7 +11,7 @@ GEM async async-container (0.18.3) async (~> 2.10) - async-http (0.77.0) + async-http (0.78.0) async (>= 2.10.2) async-pool (~> 0.7) io-endpoint (~> 0.11) @@ -79,13 +64,17 @@ GEM console (~> 1.0) msgpack (~> 1.0) date (3.3.4) - db (0.10.3) - async-io + db (0.12.0) async-pool db-mariadb (0.11.2) async-pool bigdecimal ffi-module (~> 0.3.0) + db-migrate-x (0.2.0) + db + migrate (~> 0.3) + db-model (0.5.0) + db (~> 0.11) falcon (0.48.0) async async-container (~> 0.18) @@ -99,8 +88,17 @@ GEM protocol-http (~> 0.31) protocol-rack (~> 0.7) samovar (~> 2.3) + ffi (1.17.0) + ffi (1.17.0-aarch64-linux-gnu) + ffi (1.17.0-aarch64-linux-musl) + ffi (1.17.0-arm-linux-gnu) + ffi (1.17.0-arm-linux-musl) ffi (1.17.0-arm64-darwin) + ffi (1.17.0-x86-linux-gnu) + ffi (1.17.0-x86-linux-musl) + ffi (1.17.0-x86_64-darwin) ffi (1.17.0-x86_64-linux-gnu) + ffi (1.17.0-x86_64-linux-musl) ffi-module (0.3.0) ffi fiber-annotation (0.2.0) @@ -149,7 +147,7 @@ GEM protocol-http2 (0.18.0) protocol-hpack (~> 1.4) protocol-http (~> 0.18) - protocol-rack (0.8.0) + protocol-rack (0.9.0) protocol-http (~> 0.27) rack (>= 1.0) protocol-websocket (0.17.0) @@ -174,10 +172,6 @@ GEM thread-local (1.1.0) timeout (0.4.1) traces (0.13.1) - trenni (3.14.0) - trenni-formatters (2.13.1) - mapping (~> 1.1) - trenni (~> 3.12) utopia (2.25.0) bake (~> 0.20) concurrent-ruby (~> 1.2) @@ -195,23 +189,35 @@ GEM variant (0.1.1) thread-local xrb (0.6.1) + xrb-formatters (0.1.0) + mapping (~> 1.1) + xrb (~> 0.6) xrb-sanitize (0.7.1) xrb (~> 0.3) PLATFORMS - arm64-darwin-22 - arm64-darwin-24 - x86_64-linux + aarch64-linux-gnu + aarch64-linux-musl + arm-linux-gnu + arm-linux-musl + arm64-darwin + ruby + x86-linux-gnu + x86-linux-musl + x86_64-darwin + x86_64-linux-gnu + x86_64-linux-musl DEPENDENCIES + async-http (~> 0.78.0) bake benchmark-http bundler covered db db-mariadb - db-migrate! - db-model! + db-migrate-x + db-model falcon latinum (~> 1.0) mapping (~> 1.0) @@ -222,9 +228,9 @@ DEPENDENCIES sus-fixtures-async-http sus-fixtures-async-webdriver (~> 0.2) thread-local - trenni-formatters (~> 2.0) utopia (~> 2.17) variant + xrb-formatters BUNDLED WITH - 2.4.19 + 2.5.16 diff --git a/gems.rb b/gems.rb index 14408bb..26aab79 100644 --- a/gems.rb +++ b/gems.rb @@ -11,20 +11,21 @@ gem "db" gem "db-mariadb" - gem "db-model", git: "https://github.com/socketry/db-model" - gem "db-migrate", git: "https://github.com/socketry/db-migrate" + gem "db-model" + gem "db-migrate-x" gem "migrate" gem "latinum", "~> 1.0" gem "mapping", "~> 1.0" gem "thread-local" - gem "trenni-formatters", "~> 2.0" + gem "xrb-formatters" end gem 'bake' gem 'bundler' gem 'rack-test' +gem "async-http", "~> 0.78.0" group :test do gem "sus" diff --git a/lib/vmail/account.rb b/lib/vmail/account.rb index 7050666..3b33add 100644 --- a/lib/vmail/account.rb +++ b/lib/vmail/account.rb @@ -6,6 +6,7 @@ require 'securerandom' require 'digest/sha1' require 'base64' +require 'open3' module VMail class Account @@ -53,7 +54,15 @@ def home_path end def disk_usage_string - `sudo -n du -hs #{home_path.dump}`.split(/\s+/).first + command = ["sudo", "-n", "du", "-hs", home_path] + + stdout, stderr, status = Open3.capture3(*command) + + if status.success? + stdout.split(/\s+/).first + else + "Unknown: #{stderr}" + end end def email_address diff --git a/lib/vmail/formatters.rb b/lib/vmail/formatters.rb index e36f475..3895bd9 100644 --- a/lib/vmail/formatters.rb +++ b/lib/vmail/formatters.rb @@ -1,7 +1,7 @@ -require 'trenni/formatters' -require 'trenni/formatters/html/definition_list_form' -require 'trenni/formatters/html/option_select' +require 'xrb/formatters' +require 'xrb/formatters/html/definition_list_form' +require 'xrb/formatters/html/option_select' module VMail class Attributes @@ -52,7 +52,7 @@ def assign(parameters, object) end end - class ViewFormatter < Trenni::Formatters::Formatter + class ViewFormatter < XRB::Formatters::Formatter map(Time) do |object, options| # Ensure we display the time in localtime, and show the year if it is different: if object.localtime.year != Time.now.year @@ -71,7 +71,7 @@ def approximate_number(object, **options) end def mailto(email_address) - Trenni::Builder.fragment do |builder| + XRB::Builder.fragment do |builder| builder.inline(:a, :href => "mailto:#{email_address}") { builder.text email_address } end end @@ -109,14 +109,14 @@ def self.time_ago_in_words(timestamp) end class FormFormatter < ViewFormatter - include Trenni::Formatters::HTML::DefinitionListForm + include XRB::Formatters::HTML::DefinitionListForm map(Time) do |object, options| object.httpdate end def select(**options, &block) - element(Trenni::Formatters::HTML::OptionSelect, **options, &block) + element(XRB::Formatters::HTML::OptionSelect, **options, &block) end end end diff --git a/lib/vmail/password_reset.rb b/lib/vmail/password_reset.rb index a902feb..0e0ec0b 100644 --- a/lib/vmail/password_reset.rb +++ b/lib/vmail/password_reset.rb @@ -1,7 +1,7 @@ require_relative 'domain' -require 'trenni/uri' +require 'xrb/uri' module VMail module TimestampWithoutTimeZone @@ -44,7 +44,7 @@ def flatten! end def url(domain = DOMAIN) - Trenni::URI("#{domain}/password-reset/index", id: self.id, token: self.token) + XRB::URI("#{domain}/password-reset/index", id: self.id, token: self.token) end EXPIRES_AFTER = (60 * 60 * 24 * 2) diff --git a/test/pages/login.rb b/test/pages/login.rb index c038ad2..99a195a 100644 --- a/test/pages/login.rb +++ b/test/pages/login.rb @@ -25,7 +25,7 @@ session.fill_in "password", password session.click_button "Login" - rescue => error - pp error: error.inspect + + expect(session).to have_element(xpath: "//table[@class='listing']//td[text()='test@localhost']") end end diff --git a/test/vmail/password_reset.rb b/test/vmail/password_reset.rb index 8baa8f7..498d9c1 100644 --- a/test/vmail/password_reset.rb +++ b/test/vmail/password_reset.rb @@ -22,11 +22,11 @@ expect(@password_reset.used_at).to be_nil expect(@password_reset.token).not.to be_nil - get Trenni::URI("/password-reset/index", id: @password_reset.id, token: @password_reset.token) + get XRB::URI("/password-reset/index", id: @password_reset.id, token: @password_reset.token) expect(last_response.status).to be == 200 - post Trenni::URI("/password-reset/index", id: @password_reset.id, token: @password_reset.token), { + post XRB::URI("/password-reset/index", id: @password_reset.id, token: @password_reset.token), { password_plaintext: new_password } @@ -37,7 +37,7 @@ end it "should be fail to reset password if token is invalid" do - get Trenni::URI("/password-reset/index", id: @password_reset.id, token: @password_reset.token + 'bad') + get XRB::URI("/password-reset/index", id: @password_reset.id, token: @password_reset.token + 'bad') expect(last_response.status).to be == 404 end diff --git a/test/website.rb b/test/website.rb index 1dc2717..602d0da 100644 --- a/test/website.rb +++ b/test/website.rb @@ -21,15 +21,4 @@ expect(statistics.samples).to be(:any?) expect(statistics.failed).to be(:zero?) end - - with "interactive session" do - include WebDriverContext - - it "can visit the front page" do - visit "/" - - elements = find_elements(xpath: "//*[contains(text(), 'Seamless Scalability for Ruby')]") - expect(elements).to be(:any?) - end - end end