diff options
19 files changed, 442 insertions, 39 deletions
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/build.properties b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/build.properties index 3a2d9a201..a1f8c0d9d 100644 --- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/build.properties +++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/build.properties @@ -5,3 +5,5 @@ bin.includes = META-INF/,\ testdata/,\ about.html src.includes = about.html +additional.bundles = org.eclipse.jdt.annotation +jars.extra.classpath = platform:/plugin/org.eclipse.jdt.annotation diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/config/local-default-BugzillaTests.launch b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/config/local-default-BugzillaTests.launch index 217d6eaa0..275cfb2d4 100644 --- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/config/local-default-BugzillaTests.launch +++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/config/local-default-BugzillaTests.launch @@ -24,12 +24,12 @@ <stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> <stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/> <booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/> -<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/Java SE 8 [1.8.0_65]"/> +<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/Java SE 8 [1.8.0_92]"/> <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.mylyn.bugzilla.tests.AllBugzillaTests"/> <stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog -consolelog"/> <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.mylyn.bugzilla.tests"/> <stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/> -<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xms40m -Xmx256m -XX:MaxPermSize=128m -Dorg.eclipse.mylyn.tests.all=false -Dmylyn.tests.configuration.url=http://localhost:2080/bugzilla-master"/> +<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xms40m -Xmx256m -Dorg.eclipse.mylyn.tests.all=false -Dmylyn.tests.configuration.url=http://localhost:2080/bugzilla-master"/> <stringAttribute key="pde.version" value="3.3"/> <stringAttribute key="product" value="org.eclipse.platform.ide"/> <booleanAttribute key="run_in_ui_thread" value="true"/> diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/BugzillaRestClientTest.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/BugzillaRestClientTest.java index f472b0717..b98fb489c 100644 --- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/BugzillaRestClientTest.java +++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/BugzillaRestClientTest.java @@ -42,7 +42,10 @@ import org.eclipse.mylyn.bugzilla.rest.test.support.BugzillaRestTestFixture; import org.eclipse.mylyn.commons.repositories.core.RepositoryLocation; import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationType; import org.eclipse.mylyn.commons.repositories.core.auth.UserCredentials; +import org.eclipse.mylyn.commons.sdk.util.AbstractTestFixture; import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil; +import org.eclipse.mylyn.commons.sdk.util.ConditionalIgnoreRule; +import org.eclipse.mylyn.commons.sdk.util.IFixtureJUnitClass; import org.eclipse.mylyn.commons.sdk.util.Junit4TestFixtureRunner; import org.eclipse.mylyn.commons.sdk.util.Junit4TestFixtureRunner.FixtureDefinition; import org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestClient; @@ -53,6 +56,7 @@ import org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestException; import org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestTaskAttachmentHandler; import org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestTaskSchema; import org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestVersion; +import org.eclipse.mylyn.internal.bugzilla.rest.core.IBugzillaRestConstants; import org.eclipse.mylyn.internal.bugzilla.rest.core.response.data.Field; import org.eclipse.mylyn.internal.bugzilla.rest.core.response.data.Parameters; import org.eclipse.mylyn.internal.bugzilla.rest.core.response.data.Product; @@ -87,10 +91,13 @@ import com.google.gson.Gson; // the value in the fixture. // Note: When there is no fixture with this property no tests get executed //@RunOnlyWhenProperty(property = "default", value = "1") -public class BugzillaRestClientTest { +public class BugzillaRestClientTest implements IFixtureJUnitClass { private final BugzillaRestTestFixture actualFixture; @Rule + public ConditionalIgnoreRule rule = new ConditionalIgnoreRule(this); + + @Rule public ExpectedException thrown = ExpectedException.none(); private BugzillaRestConnector connector; @@ -107,6 +114,10 @@ public class BugzillaRestClientTest { harness = actualFixture.createHarness(); } + public AbstractTestFixture getActualFixture() { + return actualFixture; + } + @Test public void testConnectorClientCache() throws Exception { BugzillaRestClient client1 = connector.getClient(actualFixture.repository()); @@ -130,21 +141,17 @@ public class BugzillaRestClientTest { } @Test - public void testInvalideUserValidate() throws BugzillaRestException { + public void testInvalidUserValidate() throws BugzillaRestException { RepositoryLocation location = new RepositoryLocation(); location.setUrl(actualFixture.getRepositoryUrl()); location.setProxy(null); location.setCredentialsStore(new InMemoryCredentialsStore()); location.setCredentials(AuthenticationType.REPOSITORY, new UserCredentials("wrong", "wrong")); - thrown.expect(BugzillaRestException.class); -// if (actualFixture.getVersion().compareTo("5.1") < 0) { - thrown.expectMessage("Unauthorized"); -// } else { -// thrown.expectMessage("Unexpected response from Bugzilla REST server"); -// } BugzillaRestClient client; client = new BugzillaRestClient(location, connector); assertNotNull(client.getClient()); + thrown.expect(BugzillaRestException.class); + thrown.expectMessage("Unauthorized"); client.validate(new NullOperationMonitor()); } @@ -155,10 +162,59 @@ public class BugzillaRestClientTest { location.setProxy(null); location.setCredentialsStore(new InMemoryCredentialsStore()); location.setCredentials(AuthenticationType.REPOSITORY, null); + BugzillaRestClient client; + client = new BugzillaRestClient(location, connector); thrown.expect(IllegalStateException.class); thrown.expectMessage("Authentication requested without valid credentials"); + client.validate(new NullOperationMonitor()); + } + + @Test + public void testInvalidPasswordValidate() throws BugzillaRestException { + RepositoryLocation location = new RepositoryLocation(); + location.setUrl(actualFixture.getRepositoryUrl()); + location.setProxy(null); + location.setCredentialsStore(new InMemoryCredentialsStore()); + location.setCredentials(AuthenticationType.REPOSITORY, new UserCredentials("tests@mylyn.eclipse.org", "wrong")); + BugzillaRestClient client; + client = new BugzillaRestClient(location, connector); + assertNotNull(client.getClient()); + thrown.expect(BugzillaRestException.class); + thrown.expectMessage("Unauthorized"); + client.validate(new NullOperationMonitor()); + } + + @Test + @ConditionalIgnoreRule.ConditionalIgnore(condition = MustRunOnApikeyRule.class) + public void testApikeyValidate() throws BugzillaRestException { + RepositoryLocation location = new RepositoryLocation(); + location.setUrl(actualFixture.getRepositoryUrl()); + location.setProxy(null); + location.setCredentialsStore(new InMemoryCredentialsStore()); + location.setCredentials(AuthenticationType.REPOSITORY, new UserCredentials("tests@mylyn.eclipse.org", "")); + location.setProperty(IBugzillaRestConstants.REPOSITORY_USE_API_KEY, Boolean.toString(true)); + location.setProperty(IBugzillaRestConstants.REPOSITORY_API_KEY, "wvkz2SoBMBQEKv6ishp1j7NY1R9l711g5w2afXc6"); + BugzillaRestClient client; + client = new BugzillaRestClient(location, connector); + assertNotNull(client.getClient()); + assertTrue(client.validate(new NullOperationMonitor())); + } + + @Test + @ConditionalIgnoreRule.ConditionalIgnore(condition = MustRunOnApikeyRule.class) + public void testInvalidApikeyValidate() throws BugzillaRestException { + RepositoryLocation location = new RepositoryLocation(); + location.setUrl(actualFixture.getRepositoryUrl()); + location.setProxy(null); + location.setCredentialsStore(new InMemoryCredentialsStore()); + location.setCredentials(AuthenticationType.REPOSITORY, new UserCredentials("tests@mylyn.eclipse.org", "")); + location.setProperty(IBugzillaRestConstants.REPOSITORY_USE_API_KEY, Boolean.toString(true)); + location.setProperty(IBugzillaRestConstants.REPOSITORY_API_KEY, "wvkz2SoBMBQEKv6ishp1j7NY1R9l711g5w2afXc8"); BugzillaRestClient client; client = new BugzillaRestClient(location, connector); + assertNotNull(client.getClient()); + thrown.expect(BugzillaRestException.class); + thrown.expectMessage("The API key you specified is invalid"); client.validate(new NullOperationMonitor()); } diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/MustRunOnApikeyRule.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/MustRunOnApikeyRule.java new file mode 100644 index 000000000..2be144852 --- /dev/null +++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/MustRunOnApikeyRule.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2016 Frank Becker and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Frank Becker - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.bugzilla.rest.core.tests; + +import org.eclipse.mylyn.bugzilla.rest.test.support.BugzillaRestTestFixture; +import org.eclipse.mylyn.commons.sdk.util.AbstractTestFixture; +import org.eclipse.mylyn.commons.sdk.util.ConditionalIgnoreRule; + +@SuppressWarnings("restriction") +public class MustRunOnApikeyRule implements ConditionalIgnoreRule.IgnoreCondition { + + @Override + public boolean isSatisfied(AbstractTestFixture fixture) { + if (fixture instanceof BugzillaRestTestFixture) { + return !((BugzillaRestTestFixture) fixture).isApiKeyEnabled(); + } else { + return false; + } + } +}
\ No newline at end of file diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/test/support/BugzillaRestTestFixture.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/test/support/BugzillaRestTestFixture.java index 8e0c9d747..f8129a590 100644 --- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/test/support/BugzillaRestTestFixture.java +++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/test/support/BugzillaRestTestFixture.java @@ -20,10 +20,15 @@ import org.eclipse.mylyn.commons.sdk.util.RepositoryTestFixture; import org.eclipse.mylyn.commons.sdk.util.TestConfiguration; import org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestConnector; import org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestCore; +import org.eclipse.mylyn.internal.bugzilla.rest.core.IBugzillaRestConstants; import org.eclipse.mylyn.tasks.core.TaskRepository; +import com.google.common.collect.ImmutableMap; + public class BugzillaRestTestFixture extends RepositoryTestFixture { + private static final String API_KEY_ENABLED_PROPERTY = "api_key_enabled"; + public final String version; protected TaskRepository repository; @@ -32,6 +37,11 @@ public class BugzillaRestTestFixture extends RepositoryTestFixture { public static final BugzillaRestTestFixture DEFAULT = discoverDefault(); + private static final ImmutableMap<String, String> userAPIKeyMap = new ImmutableMap.Builder<String, String>() + .put("admin@mylyn.eclipse.org", "XkjcuGGfDcoNx0U6uyMM8ZaNuBlEdjrmXd8In3no") //$NON-NLS-1$ + .put("tests@mylyn.eclipse.org", "wvkz2SoBMBQEKv6ishp1j7NY1R9l711g5w2afXc6") //$NON-NLS-1$ + .build(); + private static BugzillaRestTestFixture discoverDefault() { return TestConfiguration.getDefault().discoverDefault(BugzillaRestTestFixture.class, "bugzillaREST"); } @@ -73,11 +83,23 @@ public class BugzillaRestTestFixture extends RepositoryTestFixture { } repository = new TaskRepository(getConnectorKind(), getRepositoryUrl()); UserCredentials credentials = CommonTestUtil.getCredentials(PrivilegeLevel.USER); - repository.setCredentials(org.eclipse.mylyn.commons.net.AuthenticationType.REPOSITORY, - new AuthenticationCredentials(credentials.getUserName(), credentials.getPassword()), true); + if (isApiKeyEnabled()) { + repository.setProperty(IBugzillaRestConstants.REPOSITORY_USE_API_KEY, Boolean.toString(true)); + repository.setProperty(IBugzillaRestConstants.REPOSITORY_API_KEY, + userAPIKeyMap.getOrDefault(credentials.getUserName(), "")); + repository.setCredentials(org.eclipse.mylyn.commons.net.AuthenticationType.REPOSITORY, + new AuthenticationCredentials(credentials.getUserName(), ""), false); + } else { + repository.setCredentials(org.eclipse.mylyn.commons.net.AuthenticationType.REPOSITORY, + new AuthenticationCredentials(credentials.getUserName(), credentials.getPassword()), true); + } return repository; } + public boolean isApiKeyEnabled() { + return Boolean.parseBoolean(getProperty(API_KEY_ENABLED_PROPERTY)); + } + public BugzillaRestConnector connector() { return connector; } diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestClient.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestClient.java index 052b473ab..001dc545c 100644 --- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestClient.java +++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestClient.java @@ -12,6 +12,7 @@ package org.eclipse.mylyn.internal.bugzilla.rest.core; import java.io.InputStream; +import java.text.MessageFormat; import java.util.List; import java.util.Map; import java.util.Set; @@ -26,7 +27,10 @@ import org.eclipse.jdt.annotation.Nullable; import org.eclipse.mylyn.commons.core.StatusHandler; import org.eclipse.mylyn.commons.core.operations.IOperationMonitor; import org.eclipse.mylyn.commons.repositories.core.RepositoryLocation; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationType; +import org.eclipse.mylyn.commons.repositories.core.auth.UserCredentials; import org.eclipse.mylyn.commons.repositories.http.core.CommonHttpClient; +import org.eclipse.mylyn.internal.bugzilla.rest.core.response.data.BooleanResult; import org.eclipse.mylyn.internal.bugzilla.rest.core.response.data.BugzillaRestIdResult; import org.eclipse.mylyn.internal.bugzilla.rest.core.response.data.Field; import org.eclipse.mylyn.internal.bugzilla.rest.core.response.data.FieldResponse; @@ -50,6 +54,7 @@ import org.eclipse.osgi.util.NLS; import com.google.common.base.Function; import com.google.common.base.Joiner; +import com.google.common.base.Preconditions; import com.google.common.base.Strings; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; @@ -82,9 +87,27 @@ public class BugzillaRestClient { } public boolean validate(IOperationMonitor monitor) throws BugzillaRestException { - LoginToken validateResponse = new BugzillaRestLoginRequest(client).run(monitor); - if (validateResponse != null && !Strings.isNullOrEmpty(validateResponse.getId())) { + RepositoryLocation location = getClient().getLocation(); + if (location.getBooleanPropery(IBugzillaRestConstants.REPOSITORY_USE_API_KEY)) { + UserCredentials credentials = location.getCredentials(AuthenticationType.REPOSITORY); + Preconditions.checkState(credentials != null, "Authentication requested without valid credentials"); + String url = MessageFormat.format("/valid_login?login={0}&api_key={1}", //$NON-NLS-1$ + credentials.getUserName(), location.getProperty(IBugzillaRestConstants.REPOSITORY_API_KEY)); + + BooleanResult response = new BugzillaRestUnauthenticatedGetRequest<BooleanResult>(client, url, + new TypeToken<BooleanResult>() { + }).run(monitor); + return response.getResult(); + } else { + LoginToken validateResponse = new BugzillaRestLoginRequest(client).run(monitor); + if (validateResponse != null && !Strings.isNullOrEmpty(validateResponse.getId())) { + // invalide the token + String url = MessageFormat.format("/logout?token={0}", //$NON-NLS-1$ + validateResponse.getToken()); + new BugzillaRestUnauthenticatedGetRequest<BooleanResult>(client, url, new TypeToken<BooleanResult>() { + }).run(monitor); return true; + } } return false; } diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestRequest.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestRequest.java index c6cab9814..742c753a7 100644 --- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestRequest.java +++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestRequest.java @@ -13,6 +13,7 @@ package org.eclipse.mylyn.internal.bugzilla.rest.core; import static com.google.common.base.Preconditions.checkState; +import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -31,8 +32,11 @@ import org.eclipse.mylyn.commons.repositories.http.core.CommonHttpClient; import org.eclipse.mylyn.commons.repositories.http.core.CommonHttpOperation; import org.eclipse.mylyn.commons.repositories.http.core.CommonHttpResponse; import org.eclipse.mylyn.commons.repositories.http.core.HttpUtil; +import org.eclipse.mylyn.internal.bugzilla.rest.core.response.data.ErrorResponse; import org.eclipse.osgi.util.NLS; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import com.google.gson.stream.JsonWriter; public abstract class BugzillaRestRequest<T> extends CommonHttpOperation<T> { @@ -88,9 +92,15 @@ public abstract class BugzillaRestRequest<T> extends CommonHttpOperation<T> { if (!urlSuffix.endsWith("?")) { //$NON-NLS-1$ urlSuffix += "&"; //$NON-NLS-1$ } - UserCredentials credentials = getCredentials(); - urlSuffix += MessageFormat.format("Bugzilla_login={0}&Bugzilla_password={1}", //$NON-NLS-1$ - new Object[] { credentials.getUserName(), credentials.getPassword() }); + RepositoryLocation location = getClient().getLocation(); + if (location.getBooleanPropery(IBugzillaRestConstants.REPOSITORY_USE_API_KEY)) { + urlSuffix += MessageFormat.format("Bugzilla_api_key={0}", //$NON-NLS-1$ + location.getProperty(IBugzillaRestConstants.REPOSITORY_API_KEY)); + } else { + UserCredentials credentials = getCredentials(); + urlSuffix += MessageFormat.format("Bugzilla_login={0}&Bugzilla_password={1}", //$NON-NLS-1$ + credentials.getUserName(), credentials.getPassword()); + } } return baseUrl() + urlSuffix; } @@ -109,9 +119,11 @@ public abstract class BugzillaRestRequest<T> extends CommonHttpOperation<T> { protected T doProcess(CommonHttpResponse response, IOperationMonitor monitor) throws IOException, BugzillaRestException { - InputStream is = response.getResponseEntityAsStream(); - InputStreamReader in = new InputStreamReader(is); - return parseFromJson(in); + try (BufferedInputStream is = new BufferedInputStream(response.getResponseEntityAsStream())) { + InputStreamReader in = new InputStreamReader(is); + throwExeptionIfRestError(is, in); + return parseFromJson(in); + } } protected void doValidate(CommonHttpResponse response, IOperationMonitor monitor) @@ -122,7 +134,7 @@ public abstract class BugzillaRestRequest<T> extends CommonHttpOperation<T> { protected void validate(CommonHttpResponse response, int expected, IOperationMonitor monitor) throws BugzillaRestException { int statusCode = response.getStatusCode(); - if (statusCode != expected) { + if (statusCode != expected && statusCode != HttpStatus.SC_BAD_REQUEST) { if (statusCode == HttpStatus.SC_NOT_FOUND) { throw new BugzillaRestResourceNotFoundException( NLS.bind("Requested resource ''{0}'' does not exist", response.getRequestPath())); @@ -160,11 +172,15 @@ public abstract class BugzillaRestRequest<T> extends CommonHttpOperation<T> { } protected void addAuthenticationToGson(JsonWriter out, RepositoryLocation location) { - UserCredentials credentials = getCredentials(); - try { - out.name("Bugzilla_login").value(credentials.getUserName()); //$NON-NLS-1$ - out.name("Bugzilla_password").value(credentials.getPassword()); //$NON-NLS-1$ + if (location.getBooleanPropery(IBugzillaRestConstants.REPOSITORY_USE_API_KEY)) { + out.name("Bugzilla_api_key").value(location.getProperty(IBugzillaRestConstants.REPOSITORY_API_KEY)); + } else { + UserCredentials credentials = getCredentials(); + + out.name("Bugzilla_login").value(credentials.getUserName()); //$NON-NLS-1$ + out.name("Bugzilla_password").value(credentials.getPassword()); //$NON-NLS-1$ + } } catch (IOException e) { throw new BugzillaRestRuntimeException("Authentication requested with IOException", e); //$NON-NLS-1$ } @@ -175,4 +191,30 @@ public abstract class BugzillaRestRequest<T> extends CommonHttpOperation<T> { checkState(credentials != null, "Authentication requested without valid credentials"); return credentials; } + + protected ErrorResponse parseErrorResponseFromJson(InputStreamReader in) throws BugzillaRestException { + + TypeToken<ErrorResponse> a = new TypeToken<ErrorResponse>() { + }; + return new Gson().fromJson(in, a.getType()); + } + + protected void throwExeptionIfRestError(InputStream is, InputStreamReader in) + throws IOException, BugzillaRestException { + try { + is.mark(18); + byte[] b = new byte[17]; + is.read(b); + String str = new String(b); + if (str.startsWith("{\"code\":") || str.startsWith("{\"message\":") || str.startsWith("{\"error\":") //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + || str.startsWith("{\"documentation\":")) { //$NON-NLS-1$ + is.reset(); + ErrorResponse resp = parseErrorResponseFromJson(in); + throw new BugzillaRestResourceNotFoundException( + NLS.bind("Error {1}: {0}", new Object[] { resp.getMessage(), resp.getCode() })); //$NON-NLS-1$ + } + } finally { + is.reset(); + } + } } diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/IBugzillaRestConstants.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/IBugzillaRestConstants.java index 6ea53aba4..91e331241 100644 --- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/IBugzillaRestConstants.java +++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/IBugzillaRestConstants.java @@ -16,5 +16,10 @@ public interface IBugzillaRestConstants { public static final String EDITOR_TYPE_KEYWORD = "bugzilla.editor.keyword"; //$NON-NLS-1$ - public static final String BUG_STATUS = "bug_status"; + public static final String BUG_STATUS = "bug_status"; //$NON-NLS-1$ + + public static final String REPOSITORY_USE_API_KEY = "bugzilla.rest.use.apikey"; //$NON-NLS-1$ + + public static final String REPOSITORY_API_KEY = "bugzilla.rest.apikey"; //$NON-NLS-1$ + } diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/response/data/BooleanResult.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/response/data/BooleanResult.java new file mode 100644 index 000000000..cbb907f55 --- /dev/null +++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/response/data/BooleanResult.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2016 Frank Becker and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Frank Becker - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.bugzilla.rest.core.response.data; + +public class BooleanResult { + private Boolean result; + + public Boolean getResult() { + return result; + } +} diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/response/data/ErrorResponse.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/response/data/ErrorResponse.java index 03fb6572b..24bf9ba45 100644 --- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/response/data/ErrorResponse.java +++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/response/data/ErrorResponse.java @@ -18,6 +18,8 @@ public class ErrorResponse { private int code; + private String documentation; + public boolean isError() { return error; } diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/META-INF/MANIFEST.MF b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/META-INF/MANIFEST.MF index 2699545bf..9fbe69fef 100644 --- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/META-INF/MANIFEST.MF +++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/META-INF/MANIFEST.MF @@ -11,7 +11,8 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.mylyn.commons.ui;bundle-version="3.11.0", org.eclipse.mylyn.tasks.ui;bundle-version="3.11.0", org.eclipse.mylyn.tasks.core;bundle-version="3.11.0", - org.eclipse.mylyn.bugzilla.rest.core;bundle-version="1.0.0" + org.eclipse.mylyn.bugzilla.rest.core;bundle-version="1.0.0", + com.google.guava;bundle-version="15.0.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-ActivationPolicy: lazy Bundle-Vendor: Eclipse Mylyn diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/BugzillaRestRepositorySettingsPage.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/BugzillaRestRepositorySettingsPage.java index ed81d1249..43791c4bd 100644 --- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/BugzillaRestRepositorySettingsPage.java +++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/BugzillaRestRepositorySettingsPage.java @@ -13,26 +13,60 @@ package org.eclipse.mylyn.internal.bugzilla.rest.ui; import java.text.MessageFormat; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.mylyn.commons.workbench.browser.BrowserUtil; import org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestCore; +import org.eclipse.mylyn.internal.bugzilla.rest.core.IBugzillaRestConstants; +import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; +import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal; import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector; import org.eclipse.mylyn.tasks.core.TaskRepository; import org.eclipse.mylyn.tasks.ui.AbstractRepositoryConnectorUi; import org.eclipse.mylyn.tasks.ui.wizards.AbstractRepositorySettingsPage; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.browser.IWorkbenchBrowserSupport; +import org.eclipse.ui.forms.events.HyperlinkAdapter; +import org.eclipse.ui.forms.events.HyperlinkEvent; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.Hyperlink; + +import com.google.common.base.Strings; public class BugzillaRestRepositorySettingsPage extends AbstractRepositorySettingsPage { private static final String LABEL_VERSION_NUMBER = "5.0"; //$NON-NLS-1$ - private static final String DESCRIPTION = MessageFormat.format( - Messages.BugzillaRestRepositorySettingsPage_SupportsVersionMessage, - LABEL_VERSION_NUMBER); + private static final String DESCRIPTION = MessageFormat + .format(Messages.BugzillaRestRepositorySettingsPage_SupportsVersionMessage, LABEL_VERSION_NUMBER); + + private Button useApiKey; + + private Text apiKey; + + private String oldApiKeyValue; + + private Hyperlink apikeyPreferenceLink; + + private Label apiKeyLabel; + + private final String userprefs = "/userprefs.cgi?tab=apikey"; //$NON-NLS-1$ public BugzillaRestRepositorySettingsPage(TaskRepository taskRepository, AbstractRepositoryConnector connector, AbstractRepositoryConnectorUi connectorUi) { - super(Messages.BugzillaRestRepositorySettingsPage_RestRepositorySetting, DESCRIPTION, taskRepository, connector, connectorUi); + super(Messages.BugzillaRestRepositorySettingsPage_RestRepositorySetting, DESCRIPTION, taskRepository, connector, + connectorUi); setNeedsAnonymousLogin(true); setNeedsEncoding(false); - setNeedsAdvanced(false); + setNeedsAdvanced(true); setNeedsValidateOnFinish(true); } @@ -43,7 +77,100 @@ public class BugzillaRestRepositorySettingsPage extends AbstractRepositorySettin @Override protected void createAdditionalControls(Composite parent) { - // ignore + FormToolkit toolkit = new FormToolkit(TasksUiPlugin.getDefault().getFormColors(parent.getDisplay())); + Composite apiKeyContainer = new Composite(parent, SWT.NONE); + GridLayoutFactory.fillDefaults().margins(0, 0).numColumns(2).applyTo(apiKeyContainer); + GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(apiKeyContainer); + + Label useApiKeyLabel = new Label(apiKeyContainer, SWT.NONE); + useApiKeyLabel.setText(Messages.BugzillaRestRepositorySettingsPage_use_api_key); + useApiKey = new Button(apiKeyContainer, SWT.CHECK | SWT.LEFT); + useApiKey.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + boolean selectedValue = useApiKey.getSelection(); + apiKey.setEnabled(selectedValue); + if (!selectedValue) { + String apiKeyText = apiKey.getText(); + if (!Strings.isNullOrEmpty(apiKeyText)) { + oldApiKeyValue = apiKeyText; + } + apiKey.setText(""); //$NON-NLS-1$ + } else { + if (!Strings.isNullOrEmpty(oldApiKeyValue)) { + apiKey.setText(oldApiKeyValue); + } + } + } + }); + apiKeyLabel = new Label(apiKeyContainer, SWT.NONE); + apiKeyLabel.setText(Messages.BugzillaRestRepositorySettingsPage_api_key); + apiKey = new Text(apiKeyContainer, SWT.BORDER); + GridDataFactory.fillDefaults() + .grab(true, false) + .align(SWT.FILL, SWT.CENTER) + .hint(300, SWT.DEFAULT) + .applyTo(apiKey); + apiKey.setEnabled(false); + apikeyPreferenceLink = toolkit.createHyperlink(apiKeyContainer, "", SWT.NONE); //$NON-NLS-1$ + GridDataFactory.fillDefaults() + .grab(true, false) + .span(2, 1) + .align(SWT.FILL, SWT.BEGINNING) + .hint(300, SWT.DEFAULT) + .applyTo(apikeyPreferenceLink); + apikeyPreferenceLink.setBackground(apiKeyContainer.getBackground()); + apikeyPreferenceLink.addHyperlinkListener(new HyperlinkAdapter() { + @Override + public void linkActivated(HyperlinkEvent e) { + BrowserUtil.openUrl(apikeyPreferenceLink.getText(), IWorkbenchBrowserSupport.AS_EXTERNAL); + } + }); + if (repository != null) { + boolean useApiKeyValue = Boolean + .parseBoolean(repository.getProperty(IBugzillaRestConstants.REPOSITORY_USE_API_KEY)); + useApiKey.setSelection(useApiKeyValue); + String apiKeyValue = repository.getProperty(IBugzillaRestConstants.REPOSITORY_API_KEY); + apiKey.setText(Strings.nullToEmpty(apiKeyValue)); + apiKey.setEnabled(useApiKeyValue); + } + + updateURLInformation(); + serverUrlCombo.addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent e) { + updateURLInformation(); + } + }); + serverUrlCombo.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + updateURLInformation(); + } + }); + } + + protected void updateURLInformation() { + String url = serverUrlCombo.getText() + userprefs; + apiKey.setToolTipText( + NLS.bind(Messages.BugzillaRestRepositorySettingsPage_Please_create_or_copy_the_API_Key_from, url)); + apiKeyLabel.setToolTipText( + NLS.bind(Messages.BugzillaRestRepositorySettingsPage_Please_create_or_copy_the_API_Key_from, url)); + apikeyPreferenceLink.setText(url); + apikeyPreferenceLink + .setToolTipText(NLS.bind(Messages.BugzillaRestRepositorySettingsPage_View_your_apikey_settings, url)); + apikeyPreferenceLink.setEnabled(TasksUiInternal.isValidUrl(url)); + } + + @Override + public void applyTo(TaskRepository repository) { + repository.setProperty(IBugzillaRestConstants.REPOSITORY_USE_API_KEY, + Boolean.toString(useApiKey.getSelection())); + repository.setProperty(IBugzillaRestConstants.REPOSITORY_API_KEY, apiKey.getText()); + super.applyTo(repository); } } diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/Messages.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/Messages.java index 28009e885..893caaf60 100644 --- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/Messages.java +++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/Messages.java @@ -16,10 +16,18 @@ import org.eclipse.osgi.util.NLS; public class Messages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.mylyn.internal.bugzilla.rest.ui.messages"; //$NON-NLS-1$ + public static String BugzillaRestRepositorySettingsPage_api_key; + + public static String BugzillaRestRepositorySettingsPage_Please_create_or_copy_the_API_Key_from; + public static String BugzillaRestRepositorySettingsPage_RestRepositorySetting; public static String BugzillaRestRepositorySettingsPage_SupportsVersionMessage; + public static String BugzillaRestRepositorySettingsPage_use_api_key; + + public static String BugzillaRestRepositorySettingsPage_View_your_apikey_settings; + public static String BugzillaRestSearchQueryPage_PropertiesForNewQuery; public static String BugzillaRestSearchQueryPage_PropertiesForQuery; diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/messages.properties b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/messages.properties index 6300ec225..96ec9ad82 100644 --- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/messages.properties +++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/messages.properties @@ -1,5 +1,9 @@ +BugzillaRestRepositorySettingsPage_api_key=API Key +BugzillaRestRepositorySettingsPage_Please_create_or_copy_the_API_Key_from=Please create or copy the API Key from\n {0} BugzillaRestRepositorySettingsPage_RestRepositorySetting=Bugzilla REST Repository Settings BugzillaRestRepositorySettingsPage_SupportsVersionMessage=Supports Bugzilla {0} Example: https://bugs.eclipse.org/bugs/ (do not include rest.cgi) +BugzillaRestRepositorySettingsPage_use_api_key=Use API Key +BugzillaRestRepositorySettingsPage_View_your_apikey_settings=View your API key settings BugzillaRestSearchQueryPage_PropertiesForNewQuery=Properties for new Query BugzillaRestSearchQueryPage_PropertiesForQuery=Properties for Query ''{0}'' BugzillaRestTaskEditorPageFactory_Bugzilla=Bugzilla diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/provisional/bugzilla/rest/ui/BugzillaRestUiUtil.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/provisional/bugzilla/rest/ui/BugzillaRestUiUtil.java index 35618529c..a3ef85f53 100644 --- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/provisional/bugzilla/rest/ui/BugzillaRestUiUtil.java +++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/provisional/bugzilla/rest/ui/BugzillaRestUiUtil.java @@ -13,6 +13,7 @@ package org.eclipse.mylyn.internal.provisional.bugzilla.rest.ui; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestConfiguration; import org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestConnector; import org.eclipse.mylyn.internal.provisional.tasks.ui.wizards.QueryPageDetails; import org.eclipse.mylyn.internal.provisional.tasks.ui.wizards.SimpleURLQueryPageSchema; @@ -26,7 +27,10 @@ public class BugzillaRestUiUtil { BugzillaRestConnector connectorREST, TaskRepository repository) { try { SimpleURLQueryPageSchema.getInstance().initialize(taskData); - connectorREST.getRepositoryConfiguration(repository).updateProductOptions(taskData); + BugzillaRestConfiguration config = connectorREST.getRepositoryConfiguration(repository); + if (config != null) { + config.updateProductOptions(taskData); + } } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -42,7 +46,10 @@ public class BugzillaRestUiUtil { BugzillaRestConnector connectorREST, TaskRepository repository) { try { BugzillaRestSearchQueryPageSchema.getInstance().initialize(taskData); - connectorREST.getRepositoryConfiguration(repository).updateProductOptions(taskData); + BugzillaRestConfiguration config = connectorREST.getRepositoryConfiguration(repository); + if (config != null) { + config.updateProductOptions(taskData); + } } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); diff --git a/org.eclipse.mylyn.bugzilla.releng/modules/bugzilla/manifests/defaultsites.pp b/org.eclipse.mylyn.bugzilla.releng/modules/bugzilla/manifests/defaultsites.pp index 85c3db523..d28d91c6f 100644 --- a/org.eclipse.mylyn.bugzilla.releng/modules/bugzilla/manifests/defaultsites.pp +++ b/org.eclipse.mylyn.bugzilla.releng/modules/bugzilla/manifests/defaultsites.pp @@ -92,7 +92,6 @@ define bugzilla::defaultsites($base = $bugzilla::bugzillaBase, $userOwner = $bug envdefault_rest => true, testdataVersion => "Version1", } - bugzilla::site { "bugzilla-rest-master": major => "5", @@ -107,4 +106,28 @@ define bugzilla::defaultsites($base = $bugzilla::bugzillaBase, $userOwner = $bug testdataVersion => "Version2", } + bugzilla::site { "bugzilla-rest-apikey-5.0.3": + major => "5", + minor => "0", + micro => "3", + envtype => "bugzillaREST", + rest_enabled => true, + testdataVersion => "Version1", + api_key_enabled => true, + } + + bugzilla::site { "bugzilla-rest-apikey-master": + major => "5", + minor => "1", + micro => "1", + branch => "master", + branchTag => "HEAD", + envversion => "5.1.1+", + envinfo => "Master, APIKEY enabled", + envtype => "bugzillaREST", + rest_enabled => true, + testdataVersion => "Version2", + api_key_enabled => true, + } + }
\ No newline at end of file diff --git a/org.eclipse.mylyn.bugzilla.releng/modules/bugzilla/manifests/site.pp b/org.eclipse.mylyn.bugzilla.releng/modules/bugzilla/manifests/site.pp index 7be98fc2d..49f1fcb99 100644 --- a/org.eclipse.mylyn.bugzilla.releng/modules/bugzilla/manifests/site.pp +++ b/org.eclipse.mylyn.bugzilla.releng/modules/bugzilla/manifests/site.pp @@ -35,6 +35,7 @@ define bugzilla::site ( $usebugaliases = false, $clearMode = $bugzilla::clearMode, $rest_enabled = false, + $api_key_enabled = false, $envinfo = "", $testdataVersion = "", ) { @@ -82,10 +83,26 @@ define bugzilla::site ( $envinfo2 = "" } } + + if $envinfo2 != "" { + if $api_key_enabled { + $envinfo3 = "$envinfo2, APIKEY enabled" + } else { + $envinfo3 = "$envinfo2" + } + } else { + if $api_key_enabled { + $envinfo3 = "APIKEY enabled" + } else { + $envinfo3 = "" + } + } + + if $envinfo != "" { $envinfo_intern = $envinfo } else { - $envinfo_intern = $envinfo2 + $envinfo_intern = $envinfo3 } if $major == "3" { if $minor == "6" { @@ -107,7 +124,6 @@ define bugzilla::site ( timeout => 300, logoutput => true, require => Exec["prepare bugzilla"], - notify => Exec["end extract bugzilla $bugzillaDir"], } exec { "master master git clone $bugzillaDir": command => "git clone https://github.com/bugzilla/bugzilla $base/$bugzillaDir", @@ -155,7 +171,7 @@ define bugzilla::site ( user => "$userOwner", timeout => 300, creates => "$base/$bugzillaDir", - require => Exec["prepare bugzilla"], + require => Exec["$branch $branchTagInternal git fetch $bugzillaDir"], } if $branchTagInternal == "HEAD" { exec { "$branch $branchTagInternal dummy git checkout $bugzillaDir": diff --git a/org.eclipse.mylyn.bugzilla.releng/modules/bugzilla/templates/Extension.pm.erb b/org.eclipse.mylyn.bugzilla.releng/modules/bugzilla/templates/Extension.pm.erb index b61d4c014..c83928d41 100644 --- a/org.eclipse.mylyn.bugzilla.releng/modules/bugzilla/templates/Extension.pm.erb +++ b/org.eclipse.mylyn.bugzilla.releng/modules/bugzilla/templates/Extension.pm.erb @@ -83,6 +83,21 @@ sub install_before_final_checks { cryptpassword => 'mylyntest' }); } +<% if @api_key_enabled %> + my ($testuser_id_admin) = $dbh->selectrow_array( + 'SELECT userid FROM profiles WHERE login_name = ? ' , + undef, 'admin@mylyn.eclipse.org'); + my ($testuser_id_test) = $dbh->selectrow_array( + 'SELECT userid FROM profiles WHERE login_name = ? ' , + undef, 'tests@mylyn.eclipse.org'); + my $sth = $dbh->prepare( "INSERT INTO user_api_keys + (user_id, api_key, description) + VALUES (?, ?, ?)"); + $sth->execute($testuser_id_admin, 'XkjcuGGfDcoNx0U6uyMM8ZaNuBlEdjrmXd8In3no', 'Mylyn REST Connector Admin'); + $sth->execute($testuser_id_test, 'wvkz2SoBMBQEKv6ishp1j7NY1R9l711g5w2afXc6', 'Mylyn REST Connector Test'); +<% end %> + + # create two new products if (!$dbh->selectrow_array('SELECT 1 FROM products where id > 1')) { print "create additional products...\n" unless $args->{silent}; diff --git a/org.eclipse.mylyn.bugzilla.releng/modules/bugzilla/templates/service.json.erb b/org.eclipse.mylyn.bugzilla.releng/modules/bugzilla/templates/service.json.erb index 5100e00bd..e83883a17 100644 --- a/org.eclipse.mylyn.bugzilla.releng/modules/bugzilla/templates/service.json.erb +++ b/org.eclipse.mylyn.bugzilla.releng/modules/bugzilla/templates/service.json.erb @@ -14,6 +14,7 @@ <% if @branch %><% if @propertyanz.to_i > 0 %> ,<% else %> <% end %><% @propertyanz = @propertyanz.to_i -%><% @propertyanz += 1 -%>"branch": "<%= @branch %>"<% end %> <% if @branchTag %><% if @propertyanz.to_i > 0 %> ,<% else %> <% end %><% @propertyanz = @propertyanz.to_i -%><% @propertyanz += 1 -%>"branchTag": "<%= @branchTag %>"<% end %> <% if @rest_enabled %><% if @propertyanz.to_i > 0 %> ,<% else %> <% end %><% @propertyanz = @propertyanz.to_i -%><% @propertyanz += 1 -%>"rest_enabled": "<%= @rest_enabled %>"<% end %> +<% if @api_key_enabled %><% if @propertyanz.to_i > 0 %> ,<% else %> <% end %><% @propertyanz = @propertyanz.to_i -%><% @propertyanz += 1 -%>"api_key_enabled": "<%= @api_key_enabled %>"<% end %> <% if @testdataVersion %><% if @propertyanz.to_i > 0 %> ,<% else %> <% end %><% @propertyanz = @propertyanz.to_i -%><% @propertyanz += 1 -%>"testdataVersion": "<%= @testdataVersion %>"<% end %> } }
\ No newline at end of file |