This is an automated email from the ASF dual-hosted git repository. snoopdave pushed a commit to branch register-second-user-6.1.x in repository https://gitbox.apache.org/repos/asf/roller.git
commit e5b4cbcc59409a17f3e1305ea9470999a1f57704 Author: David M. Johnson <[email protected]> AuthorDate: Thu Nov 26 08:48:01 2026 -0500 Let users register after the first administrator Registration saved a new setup-completed property every time, so every registration after the first failed on the duplicate key. Only the first administrator's registration records it now, and an existing row is updated rather than inserted again. --- CHANGES.md | 3 ++ .../ui/core/security/BootstrapSecurity.java | 7 ++- .../roller/weblogger/ui/struts2/core/Register.java | 22 ++++++-- .../ui/core/security/BootstrapSecurityTest.java | 12 +++++ .../ui/struts2/core/RegisterSetupMarkerTest.java | 60 ++++++++++++++++++++++ .../ui/struts2/core/RegisterSiteUrlTest.java | 21 ++++++++ 6 files changed, 121 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 789f5df79..b767fc7fd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -132,6 +132,9 @@ ### Bug fixes +- **New users can register after the first.** Since 6.1.6, every + registration after the first administrator's failed with a database error + on the setup-completed setting, so no account was created. - **The comment filter works after editing a comment.** Saving a comment on the Comments page left the filter form with a used-up form token, so filtering then failed with an error. diff --git a/app/src/main/java/org/apache/roller/weblogger/ui/core/security/BootstrapSecurity.java b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/BootstrapSecurity.java index 3bb105a5f..3ea8732c3 100644 --- a/app/src/main/java/org/apache/roller/weblogger/ui/core/security/BootstrapSecurity.java +++ b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/BootstrapSecurity.java @@ -104,7 +104,12 @@ public final class BootstrapSecurity { // first administrator is committed. return false; } - properties.saveProperty(new RuntimeConfigProperty(COMPLETION_PROPERTY, "true")); + if (marker == null) { + marker = new RuntimeConfigProperty(COMPLETION_PROPERTY, "true"); + } else { + marker.setValue("true"); + } + properties.saveProperty(marker); weblogger.flush(); } complete(); diff --git a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Register.java b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Register.java index ce3e84e61..88e115ced 100644 --- a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Register.java +++ b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Register.java @@ -27,6 +27,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.roller.weblogger.WebloggerException; +import org.apache.roller.weblogger.business.PropertiesManager; import org.apache.roller.weblogger.business.WebloggerFactory; import org.apache.roller.weblogger.business.UserManager; import org.apache.roller.weblogger.config.AuthMethod; @@ -257,12 +258,12 @@ public class Register extends UIAction implements ServletRequestAware { // save new user mgr.addUser(ud); - WebloggerFactory.getWeblogger().getPropertiesManager().saveProperty( - new RuntimeConfigProperty(BootstrapSecurity.COMPLETION_PROPERTY, "true")); // the first administrator is the one setting up the site, so - // take the site's url from this request if none is configured + // record that setup is done and take the site's url from this + // request if none is configured if (initialAdmin) { + markSetupCompleted(); saveSiteUrlIfUnset(); } @@ -294,6 +295,21 @@ public class Register extends UIAction implements ServletRequestAware { return INPUT; } + /** + * Records that setup is done. The marker is a single row, so an existing + * one is updated rather than inserted again. + */ + static void markSetupCompleted() throws WebloggerException { + PropertiesManager properties = WebloggerFactory.getWeblogger().getPropertiesManager(); + RuntimeConfigProperty marker = properties.getProperty(BootstrapSecurity.COMPLETION_PROPERTY); + if (marker == null) { + marker = new RuntimeConfigProperty(BootstrapSecurity.COMPLETION_PROPERTY, "true"); + } else { + marker.setValue("true"); + } + properties.saveProperty(marker); + } + /** * Failing to save the site's url doesn't stop the registration; an * administrator can set it later. diff --git a/app/src/test/java/org/apache/roller/weblogger/ui/core/security/BootstrapSecurityTest.java b/app/src/test/java/org/apache/roller/weblogger/ui/core/security/BootstrapSecurityTest.java index 7b79d8170..93dbf607e 100644 --- a/app/src/test/java/org/apache/roller/weblogger/ui/core/security/BootstrapSecurityTest.java +++ b/app/src/test/java/org/apache/roller/weblogger/ui/core/security/BootstrapSecurityTest.java @@ -86,6 +86,18 @@ class BootstrapSecurityTest { verify(users, never()).getUserCount(); } + @Test + void existingUnsetMarkerIsUpdatedNotInsertedAgain() throws Exception { + RuntimeConfigProperty marker = + new RuntimeConfigProperty(BootstrapSecurity.COMPLETION_PROPERTY, "false"); + when(properties.getProperty(BootstrapSecurity.COMPLETION_PROPERTY)).thenReturn(marker); + when(users.getUserCount()).thenReturn(3L); + + assertTrue(BootstrapSecurity.completeIfInstalled(weblogger)); + verify(properties).saveProperty(org.mockito.ArgumentMatchers.same(marker)); + assertEquals("true", marker.getValue()); + } + @Test void unreadablePropertiesLeaveGateOpen() throws Exception { when(properties.getProperty(BootstrapSecurity.COMPLETION_PROPERTY)) diff --git a/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/RegisterSetupMarkerTest.java b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/RegisterSetupMarkerTest.java new file mode 100644 index 000000000..c87c77a56 --- /dev/null +++ b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/RegisterSetupMarkerTest.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.roller.weblogger.ui.struts2.core; + +import org.apache.roller.weblogger.TestUtils; +import org.apache.roller.weblogger.business.PropertiesManager; +import org.apache.roller.weblogger.business.WebloggerFactory; +import org.apache.roller.weblogger.pojos.RuntimeConfigProperty; +import org.apache.roller.weblogger.ui.core.security.BootstrapSecurity; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +/** + * Registration records that setup is done in a single properties row. Writing + * it when the row is already there must update it, not insert a second one, + * or the registration fails on the duplicate key. + */ +class RegisterSetupMarkerTest { + + @BeforeEach + void setUp() throws Exception { + TestUtils.setupWeblogger(); + } + + @Test + void recordingSetupTwiceKeepsOneRow() throws Exception { + PropertiesManager properties = WebloggerFactory.getWeblogger().getPropertiesManager(); + + Register.markSetupCompleted(); + WebloggerFactory.getWeblogger().flush(); + TestUtils.endSession(true); + + Register.markSetupCompleted(); + WebloggerFactory.getWeblogger().flush(); + TestUtils.endSession(true); + + RuntimeConfigProperty marker = properties.getProperty(BootstrapSecurity.COMPLETION_PROPERTY); + assertNotNull(marker); + assertEquals("true", marker.getValue()); + } +} diff --git a/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/RegisterSiteUrlTest.java b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/RegisterSiteUrlTest.java index a2571ed41..3149e9f66 100644 --- a/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/RegisterSiteUrlTest.java +++ b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/RegisterSiteUrlTest.java @@ -157,6 +157,27 @@ class RegisterSiteUrlTest { eq("site.absoluteurl"), any(), any()); } + @Test + void firstAdministratorRecordsSetupCompleted() throws Exception { + bootstrap.when(BootstrapSecurity::isCompleted).thenReturn(false); + bootstrap.when(() -> BootstrapSecurity.isValid(any())).thenReturn(true); + + assertEquals("success", register("https", "blog.example.org", 443).save()); + verify(properties).saveProperty(org.mockito.ArgumentMatchers.argThat( + p -> BootstrapSecurity.COMPLETION_PROPERTY.equals(p.getName()) + && "true".equals(p.getValue()))); + } + + @Test + void laterRegistrationsLeaveSetupMarkerAlone() throws Exception { + bootstrap.when(BootstrapSecurity::isCompleted).thenReturn(true); + + assertEquals("success", register("http", "other.example.net", 80).save()); + verify(users).addUser(any()); + verify(properties, never()).saveProperty(org.mockito.ArgumentMatchers.argThat( + p -> BootstrapSecurity.COMPLETION_PROPERTY.equals(p.getName()))); + } + @Test void firstAdministratorIsRegisteredEvenIfSiteUrlCannotBeSaved() throws Exception { bootstrap.when(BootstrapSecurity::isCompleted).thenReturn(false);
