Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/test/java/com/contentstack/cms/TestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public class TestClient {
/** Login password for tests that log in with a real account (null when {@code PASSWORD} is not set in {@code .env}). */
public static final String PASSWORD = env.get("PASSWORD");

/** MFA secret for accounts with two-factor on (null when {@code MFA_SECRET} is not set in {@code .env}). */
public static final String MFA_SECRET = env.get("MFA_SECRET");

/** {@code true} if {@code value} is null, empty, or whitespace-only. */
private static boolean isBlank(String value) {
return value == null || value.trim().isEmpty();
Expand Down
13 changes: 12 additions & 1 deletion src/test/java/com/contentstack/cms/stack/BranchAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
* Needs {@code EMAIL}, {@code PASSWORD} and {@code apiKey} in {@code .env} (or the environment). When any of
* them is missing the whole class is skipped with an "not run" message, which is not a pass.
* <p>
* If the account has two-factor on, also set {@code MFA_SECRET}: the login then passes it as {@code mfaSecret}
* and the SDK generates the one-time code. Without it the plain email and password login is used.
* <p>
* Branch creation is asynchronous: after each successful create the test polls the branch until fetch
* succeeds. A rejected create leaves no branch, which the API reports as 422 with error_code 905 (the same
* answer as a branch that does not exist).
Expand Down Expand Up @@ -103,7 +106,15 @@ static void setup() throws Exception {
Assumptions.assumeTrue(apiKeyConfigured, "not run: apiKey is not set in .env");

client = new Contentstack.Builder().setHost(TestClient.DEV_HOST).build();
Response<LoginDetails> login = client.login(email, password);
Response<LoginDetails> login;
if (isSet(TestClient.MFA_SECRET)) {
// The account has two-factor on: let the SDK generate the TOTP from the secret.
HashMap<String, String> mfaParams = new HashMap<>();
mfaParams.put("mfaSecret", TestClient.MFA_SECRET);
login = client.login(email, password, mfaParams);
} else {
login = client.login(email, password);
}
assertTrue(login.isSuccessful(), "login with EMAIL / PASSWORD should succeed");
loggedIn = true;

Expand Down
Loading