7 Commits

Author SHA1 Message Date
d8a35ac3fd Merge pull request 'Fix wrong redirect after sign-in for RS OAuth' (#146) from bugfix/rs_oauth_login into master
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #146
Reviewed-by: galfert <garret.alfert@gmail.com>
2023-09-05 11:03:02 +00:00
Râu Cao
a91ee2bd0a Fix generated usernames in seeds potentially being too short
All checks were successful
continuous-integration/drone/push Build is passing
2023-09-04 11:35:51 +02:00
Râu Cao
fcb6923c92 Fix wrong redirect after sign-in for RS OAuth
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
Release Drafter / Update release notes draft (pull_request) Successful in 3s
We use a custom auth method to pre-fill the username when reaching the
RS OAuth while signed out. However, it needs to redirect back to the RS
OAuth page after sign-in, and not to the root path.
2023-09-04 11:33:16 +02:00
Râu Cao
0f3b9f176e 0.8.1
All checks were successful
continuous-integration/drone/push Build is passing
2023-09-03 15:35:46 +02:00
822ae2f945 Merge pull request 'Fix migration failing with PostgreSQL' (#145) from bugfix/144-postgres_migration into master
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #145
2023-09-03 13:32:36 +00:00
Râu Cao
96c669ab4e Update database schema, fix spec
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
Release Drafter / Update release notes draft (pull_request) Successful in 2s
2023-09-03 15:29:09 +02:00
Râu Cao
558100c35e Fix migration failing with PostgreSQL 2023-09-03 15:28:32 +02:00
8 changed files with 33 additions and 6 deletions

View File

@@ -37,4 +37,8 @@ class ApplicationController < ActionController::Base
format.any { head status } format.any { head status }
end end
end end
def after_sign_in_path_for(user)
session[:user_return_to] || root_path
end
end end

View File

@@ -108,6 +108,7 @@ class Rs::OauthController < ApplicationController
def require_signed_in_with_username def require_signed_in_with_username
unless user_signed_in? unless user_signed_in?
username, org = params[:useraddress].split("@") username, org = params[:useraddress].split("@")
session[:user_return_to] = request.url
redirect_to new_user_session_path(cn: username, ou: org) redirect_to new_user_session_path(cn: username, ou: org)
end end
end end

View File

@@ -1,9 +1,12 @@
class CreateRemoteStorageAuthorizations < ActiveRecord::Migration[7.0] class CreateRemoteStorageAuthorizations < ActiveRecord::Migration[7.0]
def change def change
db_type = ActiveRecord::Base.configurations.find_db_config(Rails.env).adapter
array_default = db_type == "postgresql" ? [] : [].to_yaml
create_table :remote_storage_authorizations do |t| create_table :remote_storage_authorizations do |t|
t.references :user, null: false, foreign_key: true t.references :user, null: false, foreign_key: true
t.string :token t.string :token
t.text :permissions, array: true, default: [].to_yaml t.text :permissions, array: true, default: array_default
t.string :client_id t.string :client_id
t.string :redirect_uri t.string :redirect_uri
t.string :app_name t.string :app_name

View File

@@ -84,13 +84,12 @@ ActiveRecord::Schema[7.0].define(version: 2023_05_23_120753) do
t.datetime "confirmed_at", precision: nil t.datetime "confirmed_at", precision: nil
t.datetime "confirmation_sent_at", precision: nil t.datetime "confirmation_sent_at", precision: nil
t.string "unconfirmed_email" t.string "unconfirmed_email"
t.text "ln_login_ciphertext"
t.text "ln_password_ciphertext" t.text "ln_password_ciphertext"
t.string "ln_account" t.string "ln_account"
t.string "nostr_pubkey"
t.datetime "remember_created_at" t.datetime "remember_created_at"
t.string "remember_token" t.string "remember_token"
t.text "preferences" t.text "preferences"
t.string "nostr_pubkey"
t.index ["email"], name: "index_users_on_email", unique: true t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end end

View File

@@ -13,6 +13,7 @@ Sidekiq::Testing.inline! do
35.times do |n| 35.times do |n|
username = Faker::Name.unique.first_name.downcase username = Faker::Name.unique.first_name.downcase
email = Faker::Internet.unique.email email = Faker::Internet.unique.email
next if username.length < 3
CreateAccount.call( CreateAccount.call(
username: username, domain: "kosmos.org", email: email, username: username, domain: "kosmos.org", email: email,

View File

@@ -11,7 +11,7 @@
"postcss-preset-env": "^7.8.3", "postcss-preset-env": "^7.8.3",
"tailwindcss": "^3.2.4" "tailwindcss": "^3.2.4"
}, },
"version": "0.8.0", "version": "0.8.1",
"scripts": { "scripts": {
"build:css:tailwind": "tailwindcss --postcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css", "build:css:tailwind": "tailwindcss --postcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css",
"build:css": "yarn run build:css:tailwind" "build:css": "yarn run build:css:tailwind"

View File

@@ -54,6 +54,11 @@ RSpec.describe 'remoteStorage OAuth Dialog', type: :feature do
context "when signed out" do context "when signed out" do
let(:user) { create :user } let(:user) { create :user }
before do
allow_any_instance_of(User).to receive(:valid_ldap_authentication?)
.with(user.password).and_return(true)
end
it "prefills the username field in the signin form" do it "prefills the username field in the signin form" do
visit new_rs_oauth_path(useraddress: user.address, visit new_rs_oauth_path(useraddress: user.address,
redirect_uri: "http://example.com", redirect_uri: "http://example.com",
@@ -62,5 +67,19 @@ RSpec.describe 'remoteStorage OAuth Dialog', type: :feature do
expect(find("#user_cn").value).to eq(user.cn) expect(find("#user_cn").value).to eq(user.cn)
end end
it "redirects to the OAuth dialog after sign-in" do
auth_url = new_rs_oauth_url(useraddress: user.address,
redirect_uri: "http://example.com",
client_id: "http://example.com",
scope: "documents,[photos], contacts:r")
visit auth_url
fill_in "User", with: user.cn
fill_in "Password", with: user.password
click_button "Log in"
expect(current_url).to eq(auth_url)
end
end end
end end

View File

@@ -25,7 +25,7 @@ RSpec.describe CreateLndhubAccountJob, type: :job do
context "with existing credentials stored" do context "with existing credentials stored" do
before do before do
user.ln_login = "foo" user.ln_account = "foo"
user.ln_password = "bar" user.ln_password = "bar"
user.save! user.save!
end end
@@ -36,7 +36,7 @@ RSpec.describe CreateLndhubAccountJob, type: :job do
expect(WebMock).to_not have_requested(:post, "http://localhost:3023/create") expect(WebMock).to_not have_requested(:post, "http://localhost:3023/create")
user.reload user.reload
expect(user.ln_login).to eq("foo") expect(user.ln_account).to eq("foo")
expect(user.ln_password).to eq("bar") expect(user.ln_password).to eq("bar")
end end
end end