From 6e9bac554870e4a7187ec8a24be96be8562d4311 Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Thu, 7 May 2020 14:46:19 +0200 Subject: [PATCH 01/11] Use single backups EP constant --- bubble-server/src/main/java/bubble/ApiConstants.java | 1 - .../src/main/java/bubble/model/cloud/BubbleBackup.java | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/bubble-server/src/main/java/bubble/ApiConstants.java b/bubble-server/src/main/java/bubble/ApiConstants.java index 4bbb63f5..bc33f25e 100644 --- a/bubble-server/src/main/java/bubble/ApiConstants.java +++ b/bubble-server/src/main/java/bubble/ApiConstants.java @@ -122,7 +122,6 @@ public class ApiConstants { public static final String DOMAINS_ENDPOINT = "/domains"; public static final String PLANS_ENDPOINT = "/plans"; public static final String FOOTPRINTS_ENDPOINT = "/footprints"; - public static final String BACKUPS_ENDPOINT = "/backups"; public static final String EP_CLEAN_BACKUPS = "/clean"; public static final String PAYMENT_METHODS_ENDPOINT = "/paymentMethods"; diff --git a/bubble-server/src/main/java/bubble/model/cloud/BubbleBackup.java b/bubble-server/src/main/java/bubble/model/cloud/BubbleBackup.java index 3e185fb9..e9534f67 100644 --- a/bubble-server/src/main/java/bubble/model/cloud/BubbleBackup.java +++ b/bubble-server/src/main/java/bubble/model/cloud/BubbleBackup.java @@ -20,7 +20,7 @@ import javax.persistence.*; import javax.validation.constraints.Pattern; import javax.validation.constraints.Size; -import static bubble.ApiConstants.BACKUPS_ENDPOINT; +import static bubble.ApiConstants.EP_BACKUPS; import static bubble.ApiConstants.ERROR_MAXLEN; import static bubble.service.backup.BackupService.BR_STATE_LOCK_TIMEOUT; import static org.cobbzilla.util.daemon.ZillaRuntime.empty; @@ -29,7 +29,7 @@ import static org.cobbzilla.wizard.model.crypto.EncryptedTypes.ENCRYPTED_STRING; import static org.cobbzilla.wizard.model.crypto.EncryptedTypes.ENC_PAD; @ECType(root=true, name="backup") @ECTypeCreate(method="DISABLED") -@ECTypeURIs(baseURI=BACKUPS_ENDPOINT, listFields={"network", "label", "path"}) +@ECTypeURIs(baseURI=EP_BACKUPS, listFields={"network", "label", "path"}) @Entity @NoArgsConstructor @Accessors(chain=true) @ECIndexes({ @ECIndex(unique=true, of={"network", "path"}) }) public class BubbleBackup extends IdentifiableBase implements HasAccount { -- 2.17.1 From aebe38683581ea5490d6f7cdea61eec28e5df4aa Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Thu, 7 May 2020 14:47:03 +0200 Subject: [PATCH 02/11] Allow different then default root password in live tests --- .../bubble/test/live/BackupRestoreTest.java | 2 ++ .../java/bubble/test/live/LiveTestBase.java | 29 ++++++++++++------- .../models/tests/live/backup_and_restore.json | 3 +- .../models/tests/live/fork_sage.json | 2 +- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/bubble-server/src/test/java/bubble/test/live/BackupRestoreTest.java b/bubble-server/src/test/java/bubble/test/live/BackupRestoreTest.java index 5f66029a..0bb7c5a7 100644 --- a/bubble-server/src/test/java/bubble/test/live/BackupRestoreTest.java +++ b/bubble-server/src/test/java/bubble/test/live/BackupRestoreTest.java @@ -15,6 +15,8 @@ public class BackupRestoreTest extends LiveTestBase { final String fqdn = System.getenv("BUBBLE_BACKUP_RESTORE_SAGE"); return empty(fqdn) ? die("getTestSageFqdn: BUBBLE_BACKUP_RESTORE_SAGE env var not defined") : fqdn; } + // If not default, remember to set `TEST_SAGE_ROOT_PASS` properly also. + @Override protected boolean shouldStopSage() { return false; } @Override public boolean backupsEnabled() { return true; } diff --git a/bubble-server/src/test/java/bubble/test/live/LiveTestBase.java b/bubble-server/src/test/java/bubble/test/live/LiveTestBase.java index 9e0a84de..cc0b1bfc 100644 --- a/bubble-server/src/test/java/bubble/test/live/LiveTestBase.java +++ b/bubble-server/src/test/java/bubble/test/live/LiveTestBase.java @@ -11,8 +11,10 @@ import org.junit.After; import org.junit.AfterClass; import org.junit.Before; +import java.util.AbstractMap; import java.util.concurrent.atomic.AtomicReference; +import static org.cobbzilla.util.daemon.ZillaRuntime.empty; import static org.junit.Assert.fail; @Slf4j @@ -21,27 +23,34 @@ public class LiveTestBase extends NetworkTestBase { @Override protected boolean useMocks() { return false; } protected String getTestSageFqdn() { return System.getenv("TEST_SAGE_FQDN"); } + protected String getTestSageRootPass() { + final var envRootPass = System.getenv("TEST_SAGE_ROOT_PASS"); + return (!empty(envRootPass)) ? envRootPass : ROOT_PASSWORD; + } protected boolean shouldStopSage() { return true; } - private static final AtomicReference sageFqdn = new AtomicReference<>(); + private static final AtomicReference> sageFqdnAndRootPass = + new AtomicReference<>(); private static final AtomicReference testInstance = new AtomicReference<>(); @Before public void startSage () throws Exception { - synchronized (sageFqdn) { - if (sageFqdn.get() == null) { - final String envSage = getTestSageFqdn(); + synchronized (sageFqdnAndRootPass) { + if (sageFqdnAndRootPass.get() == null) { + final var envSage = getTestSageFqdn(); + final var rootPass = getTestSageRootPass(); if (envSage != null) { - sageFqdn.set(envSage); + sageFqdnAndRootPass.set(new AbstractMap.SimpleEntry<>(envSage, rootPass)); } else { modelTest("live/fork_sage"); - final NewNodeNotification newNetwork = (NewNodeNotification) getApiRunner().getContext().get("newNetwork"); + final var newNetwork = (NewNodeNotification) getApiRunner().getContext().get("newNetwork"); if (newNetwork == null) fail("newNetwork not found in context after fork"); if (newNetwork.getFqdn() == null) fail("newNetwork.fqdn was null after fork"); - sageFqdn.set(newNetwork.getFqdn()); + sageFqdnAndRootPass.set(new AbstractMap.SimpleEntry<>(newNetwork.getFqdn(), rootPass)); } } } - getApiRunner().getContext().put("sageFqdn", sageFqdn.get()); + getApiRunner().getContext().put("sageFqdn", sageFqdnAndRootPass.get().getKey()); + getApiRunner().getContext().put("sageRootPass", sageFqdnAndRootPass.get().getValue()); } @After public void saveTestInstance() throws Exception { testInstance.set(this); } @@ -49,10 +58,10 @@ public class LiveTestBase extends NetworkTestBase { @AfterClass public static void stopSage () throws Exception { final LiveTestBase liveTest = testInstance.get(); if (liveTest == null) { - log.warn("testInstance was never set, cannot stop sage: "+sageFqdn.get()); + log.warn("testInstance was never set, cannot stop sage: " + sageFqdnAndRootPass.get()); } else { if (liveTest.shouldStopSage()) { - final String fqdn = sageFqdn.get(); + final var fqdn = sageFqdnAndRootPass.get().getKey(); if (fqdn == null) { log.warn("stopSage: sage FQDN never got set"); } else { diff --git a/bubble-server/src/test/resources/models/tests/live/backup_and_restore.json b/bubble-server/src/test/resources/models/tests/live/backup_and_restore.json index 91e33d64..84f6ed7f 100644 --- a/bubble-server/src/test/resources/models/tests/live/backup_and_restore.json +++ b/bubble-server/src/test/resources/models/tests/live/backup_and_restore.json @@ -10,7 +10,7 @@ "uri": "auth/login", "entity": { "username": "root", - "password": "password1!" + "password": "{{sageRootPass}}" } }, "response": { @@ -51,6 +51,7 @@ "include": "new_bubble", "params": { "sageFqdn": "{{sageFqdn}}", + "rootPassword": "{{sageRootPass}}", "username": "bubble-user", "password": "password1!", "userSessionVar": "userSession", diff --git a/bubble-server/src/test/resources/models/tests/live/fork_sage.json b/bubble-server/src/test/resources/models/tests/live/fork_sage.json index e748b723..0f597f36 100644 --- a/bubble-server/src/test/resources/models/tests/live/fork_sage.json +++ b/bubble-server/src/test/resources/models/tests/live/fork_sage.json @@ -23,7 +23,7 @@ "uri": "auth/login", "entity": { "name": "root", - "password": "password1!" + "password": "{{sageRootPass}}" } }, "response": { -- 2.17.1 From 4428482bb25ce41b70ad5e7f42460600447d4b1b Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Fri, 8 May 2020 11:38:34 +0200 Subject: [PATCH 03/11] Use proper method to get domain for test bubble --- .../src/test/java/bubble/test/live/BackupRestoreTest.java | 3 +++ utils/cobbzilla-utils | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/bubble-server/src/test/java/bubble/test/live/BackupRestoreTest.java b/bubble-server/src/test/java/bubble/test/live/BackupRestoreTest.java index 0bb7c5a7..c0b19300 100644 --- a/bubble-server/src/test/java/bubble/test/live/BackupRestoreTest.java +++ b/bubble-server/src/test/java/bubble/test/live/BackupRestoreTest.java @@ -8,6 +8,7 @@ import org.junit.Test; import static org.cobbzilla.util.daemon.ZillaRuntime.die; import static org.cobbzilla.util.daemon.ZillaRuntime.empty; +import static org.cobbzilla.util.http.URIUtil.hostToDomain; public class BackupRestoreTest extends LiveTestBase { @@ -21,6 +22,8 @@ public class BackupRestoreTest extends LiveTestBase { @Override public boolean backupsEnabled() { return true; } + @Override public String getDefaultDomain() { return hostToDomain(getTestSageFqdn()); } + @Test public void testBackupAndRestore () throws Exception { modelTest("live/backup_and_restore"); } } diff --git a/utils/cobbzilla-utils b/utils/cobbzilla-utils index 156aed32..f57f28cc 160000 --- a/utils/cobbzilla-utils +++ b/utils/cobbzilla-utils @@ -1 +1 @@ -Subproject commit 156aed329eadea96c9059fe671907707a726c355 +Subproject commit f57f28cc912e30c03d4db32443378440f1399120 -- 2.17.1 From de146be44fe82625ada6084dc533cacf1c01de37 Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Fri, 8 May 2020 11:38:58 +0200 Subject: [PATCH 04/11] Use proper conditions in test for existing contact --- .../test/resources/models/include/add_approved_contact.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bubble-server/src/test/resources/models/include/add_approved_contact.json b/bubble-server/src/test/resources/models/include/add_approved_contact.json index 0a3952aa..c6d9b504 100644 --- a/bubble-server/src/test/resources/models/include/add_approved_contact.json +++ b/bubble-server/src/test/resources/models/include/add_approved_contact.json @@ -31,7 +31,7 @@ { "comment": "add <> contact for user <>", - "unless": "existingContact.getInfo() == '<>'", + "unless": "existingContact.getUuid() != null", "request": { "session": "<>", "uri": "users/<>/policy/contacts", @@ -47,7 +47,7 @@ { "comment": "resend verification message for <>/<> for user <>", - "onlyIf": "existingContact.getInfo() == '<>'", + "onlyIf": "existingContact.getUuid() != null", "request": { "session": "<>", "uri": "users/<>/policy/contacts/verify", -- 2.17.1 From 38a99814e806b2a7978238e178a04af26e962344 Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Fri, 8 May 2020 12:09:56 +0200 Subject: [PATCH 05/11] Update lib --- utils/cobbzilla-wizard | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/cobbzilla-wizard b/utils/cobbzilla-wizard index 1b2c4ade..e6c331bd 160000 --- a/utils/cobbzilla-wizard +++ b/utils/cobbzilla-wizard @@ -1 +1 @@ -Subproject commit 1b2c4adef489e38bb3e488bf995db79d50fea138 +Subproject commit e6c331bdc4a8898ef9a7a5bcd44dd45a40c1880a -- 2.17.1 From 816e3bcedc6faa2f675b01e9db136945d65c96b1 Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Fri, 8 May 2020 13:44:51 +0200 Subject: [PATCH 06/11] Remove not needed duplicated check in the test --- .../models/tests/live/backup_and_restore.json | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/bubble-server/src/test/resources/models/tests/live/backup_and_restore.json b/bubble-server/src/test/resources/models/tests/live/backup_and_restore.json index 84f6ed7f..2a05b3b0 100644 --- a/bubble-server/src/test/resources/models/tests/live/backup_and_restore.json +++ b/bubble-server/src/test/resources/models/tests/live/backup_and_restore.json @@ -20,19 +20,8 @@ } }, - { - "comment": "load root account policy", - "request": { - "uri": "users/root/policy" - }, - "response": { - "store": "rootPolicy" - } - }, - { "comment": "add root@example.com as email contact for root user, if not already present", - "onlyIf": "!rootPolicy.hasContact('root@example.com')", "include": "add_approved_contact", "params": { "username": "root", -- 2.17.1 From e590f3af398c803ecc47fb7787bd7a5a30fcdbf9 Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Fri, 8 May 2020 13:45:08 +0200 Subject: [PATCH 07/11] Add payment method for when needed in the test --- .../resources/models/include/new_bubble.json | 48 +++++++++++++++++-- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/bubble-server/src/test/resources/models/include/new_bubble.json b/bubble-server/src/test/resources/models/include/new_bubble.json index 2065b76a..1b1d25af 100644 --- a/bubble-server/src/test/resources/models/include/new_bubble.json +++ b/bubble-server/src/test/resources/models/include/new_bubble.json @@ -94,8 +94,47 @@ }, { + "comment": "add email contact for the new user, if not already present", + "include": "add_approved_contact", + "params": { + "username": "<>", + "userSession": "<>", + "userConnection": "<>", + "rootSession": "rootSession", + "rootConnection": "<>", + "contactInfo": "<>", + "contactLookup": "<>", + "authFactor": "not_required" + } + }, + + { + "comment": "list all payment methods", + "request": { "uri": "me/paymentMethods?all=true" }, + "response": { "store": "paymentMethods" } + }, + + { + "comment": "add payment method for the user", + "onlyIf": "len(paymentMethods) == 0", + "before": "stripe_tokenize_card", + "request": { + "uri": "me/paymentMethods", + "method": "put", + "entity": { "paymentMethodType": "credit", "paymentInfo": "{{stripeToken}}" } + } + }, + + { + "comment": "list all payment methods again after creating one", + "onlyIf": "len(paymentMethods) == 0", + "request": { "uri": "me/paymentMethods?all=true" }, + "response": { "store": "paymentMethods", "check": [{ "condition": "len(json) == 1" }] } + }, + + { + "comment": "add plan, using the first found payment method for the new bubble", "before": "sleep 24s", - "comment": "add plan", "request": { "uri": "me/plans", "method": "put", @@ -105,12 +144,11 @@ "locale": "<>", "timezone": "<>", "plan": "<>", - "footprint": "<>" + "footprint": "<>", + "paymentMethodObject": { "uuid": "{{ paymentMethods.[0].uuid }}" } } }, - "response": { - "store": "plan" - } + "response": { "store": "plan" } }, { -- 2.17.1 From 0133c546b55bd1e25d58f76fab8a19edd4bba6e1 Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Fri, 8 May 2020 14:02:36 +0200 Subject: [PATCH 08/11] Move comment to be the first line in script parts --- .../src/test/resources/models/include/new_bubble.json | 4 ++-- .../test/resources/models/tests/live/backup_and_restore.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bubble-server/src/test/resources/models/include/new_bubble.json b/bubble-server/src/test/resources/models/include/new_bubble.json index 1b1d25af..3c7ca562 100644 --- a/bubble-server/src/test/resources/models/include/new_bubble.json +++ b/bubble-server/src/test/resources/models/include/new_bubble.json @@ -163,8 +163,8 @@ }, { - "before": "await_url me/networks/<>/dns/find?type=A&name=.<>.<> 40m 10s await_json.length > 0", "comment": "list DNS for the network, should now see a DNS A record for new instance", + "before": "await_url me/networks/<>/dns/find?type=A&name=.<>.<> 40m 10s await_json.length > 0", "request": { "uri": "me/networks/<>/dns/find?type=A&name=.<>.<>" }, @@ -177,8 +177,8 @@ }, { - "before": "await_url .bubble 40m 20s", "comment": "call API of deployed node, ensure it is running", + "before": "await_url .bubble 40m 20s", "connection": { "name": "<>", "baseUri": "https://{{<>.host}}.<>.<>:{{serverConfig.nginxPort}}/api" diff --git a/bubble-server/src/test/resources/models/tests/live/backup_and_restore.json b/bubble-server/src/test/resources/models/tests/live/backup_and_restore.json index 2a05b3b0..f259778c 100644 --- a/bubble-server/src/test/resources/models/tests/live/backup_and_restore.json +++ b/bubble-server/src/test/resources/models/tests/live/backup_and_restore.json @@ -53,8 +53,8 @@ }, { - "before": "await_url .bubble 40m 20s", "comment": "add file to storage", + "before": "await_url .bubble 40m 20s", "connection": { "name": "bubbleConnection" }, "request": { "session": "bubbleUserSession", -- 2.17.1 From c1cdc06f0391645e471c456c887648b038c11765 Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Fri, 8 May 2020 14:02:55 +0200 Subject: [PATCH 09/11] Set sendMetrics where needed in test --- .../src/test/resources/models/include/new_bubble.json | 4 +++- .../test/resources/models/tests/live/backup_and_restore.json | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/bubble-server/src/test/resources/models/include/new_bubble.json b/bubble-server/src/test/resources/models/include/new_bubble.json index 3c7ca562..2b121284 100644 --- a/bubble-server/src/test/resources/models/include/new_bubble.json +++ b/bubble-server/src/test/resources/models/include/new_bubble.json @@ -22,7 +22,8 @@ "region": "New Jersey", "bubbleConnectionVar": "bubbleConnection", "bubbleUserSessionVar": "bubbleUserSession", - "bubbleUserVar": "bubbleUserAccount" + "bubbleUserVar": "bubbleUserAccount", + "sendMetrics": null } }, @@ -145,6 +146,7 @@ "timezone": "<>", "plan": "<>", "footprint": "<>", + "sendMetrics": <>, "paymentMethodObject": { "uuid": "{{ paymentMethods.[0].uuid }}" } } }, diff --git a/bubble-server/src/test/resources/models/tests/live/backup_and_restore.json b/bubble-server/src/test/resources/models/tests/live/backup_and_restore.json index f259778c..92cef50a 100644 --- a/bubble-server/src/test/resources/models/tests/live/backup_and_restore.json +++ b/bubble-server/src/test/resources/models/tests/live/backup_and_restore.json @@ -48,7 +48,8 @@ "email": "bubble-user@example.com", "plan": "bubble", "networkVar": "bubbleNetwork", - "bubbleConnectionVar": "bubbleConnection" + "bubbleConnectionVar": "bubbleConnection", + "sendMetrics": true } }, -- 2.17.1 From a9876ee23792d8e731a63b5ef59fbf0740823f97 Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Mon, 18 May 2020 17:06:33 +0200 Subject: [PATCH 10/11] Update lib --- utils/cobbzilla-utils | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/cobbzilla-utils b/utils/cobbzilla-utils index f57f28cc..45579ec8 160000 --- a/utils/cobbzilla-utils +++ b/utils/cobbzilla-utils @@ -1 +1 @@ -Subproject commit f57f28cc912e30c03d4db32443378440f1399120 +Subproject commit 45579ec8407102a82dceae37df8d23f1ab1b9686 -- 2.17.1 From 6083db0cf309ed72e0674e81c82e15b1388dd41e Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Tue, 19 May 2020 18:51:49 -0400 Subject: [PATCH 11/11] update lib --- utils/cobbzilla-wizard | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/cobbzilla-wizard b/utils/cobbzilla-wizard index 5e9baa01..2a086ae6 160000 --- a/utils/cobbzilla-wizard +++ b/utils/cobbzilla-wizard @@ -1 +1 @@ -Subproject commit 5e9baa01f6b7b9cfc765dc7f404aa53d84535586 +Subproject commit 2a086ae6d7887b42b647db33e241cfada5574a2e -- 2.17.1