mraible commented on code in PR #399:
URL: https://github.com/apache/roller/pull/399#discussion_r4711141800


##########
app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/EntryRemove.java:
##########
@@ -106,7 +109,7 @@ public String remove() {
                 // note to user
                 addMessage("weblogEdit.entryRemoved", entry.getTitle());
 
-                return SUCCESS;
+                return canListEntries() ? SUCCESS : SUCCESS_EDITOR;

Review Comment:
   Nit: `canListEntries()` runs after `removeWeblogEntry()` and `flush()` have 
committed and the "entry deleted" message is added. If its permission lookup 
throws a `WebloggerException`, the catch adds `generic.error.check.logs` and 
returns `INPUT`, so the user sees "Are you sure you want to delete this entry?" 
again for an entry that's already gone, and confirming returns `ERROR`.
   
   Working out the result outside the delete's `try`, or catching inside 
`canListEntries()` and falling back to `SUCCESS_EDITOR`, would avoid that.



##########
app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Register.java:
##########
@@ -294,6 +295,21 @@ public String save() {
         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 {

Review Comment:
   Older than this PR, so fine to leave: the read-then-insert here isn't 
atomic. If the first registration is submitted twice at once (same session, so 
`isValid` passes both times), both requests have `initialAdmin` true, both see 
no marker, and the second flush fails on the duplicate key with "check logs". 
Catching that and re-reading, or serializing the initial-admin path the way 
`redeem` is `synchronized`, would close it.



##########
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();
+

Review Comment:
   Nit: this commits `bootstrap.completed=true` to the shared test database and 
never removes it, so a later database-backed test that expects a fresh install, 
or calls `completeIfInstalled` with no users, could see setup as done depending 
on test order. Removing or restoring the property in an `@AfterEach` would keep 
it isolated.



##########
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();

Review Comment:
   Nit: the name says it keeps one row, but `getProperty` reads by primary key, 
so it returns one row either way. It also doesn't cover the case that failed, a 
second registration through `save()` once setup is complete. If the marker 
write moved back into the unconditional path in `save()`, this would still 
pass, and the mocked `RegisterSiteUrlTest` wouldn't catch a flush failure. 
Driving a second registration through `save()` against the database, or 
renaming the test to what it checks, would help.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to