Skip to content
This repository was archived by the owner on Nov 23, 2021. It is now read-only.
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.cookie.BasicClientCookie;
import org.apache.http.message.BasicNameValuePair;
import org.openqa.selenium.Cookie;
import org.slf4j.Logger;
Expand Down Expand Up @@ -65,8 +64,8 @@ public class AemAuthCookieFactory {
/**
* This method provides browser cookie for authenticating user to AEM instance
*
* @param url URL to AEM instance, like http://localhost:4502
* @param login Username to use
* @param url URL to AEM instance, like http://localhost:4502
* @param login Username to use
* @param password Password to use
* @return Cookie for selenium WebDriver.
*/
Expand All @@ -84,10 +83,6 @@ public Cookie getCookie(String url, String login, String password) {
CookieStore cookieStore = new BasicCookieStore();
HttpClientContext context = HttpClientContext.create();

if ("true".equals(properties.getProperty(ConfigKeys.WEBDRIVER_PROXY_COOKIE))) {
addProxyCookie(cookieStore);
}

context.setCookieStore(cookieStore);

try {
Expand Down Expand Up @@ -126,13 +121,4 @@ private Cookie findAuthenticationCookie(List<org.apache.http.cookie.Cookie> cook
}
return null;
}

private void addProxyCookie(CookieStore cookieStore) {
BasicClientCookie proxyCookie = new BasicClientCookie(
properties.getProperty(ConfigKeys.WEBDRIVER_PROXY_COOKIE_NAME),
properties.getProperty(ConfigKeys.WEBDRIVER_PROXY_COOKIE_VALUE));
proxyCookie.setDomain(properties.getProperty(ConfigKeys.WEBDRIVER_PROXY_COOKIE_DOMAIN));
proxyCookie.setPath("/");
cookieStore.addCookie(proxyCookie);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,6 @@ protected void configure() {
.to(PublishProperties.class);
bind(InstanceProperties.class).annotatedWith(Names.named(AemConfigFilenames.AUTHOR_PROPERTIES))
.to(AuthorProperties.class);

// copy "publish.url" value to "base.url" fields used in bb-core
requestInjection(new Object() {
@Inject
public void init(Properties properties) {
String publishUrl = properties.getProperty(AemConfigKeys.PUBLISH_URL);
properties.put(ConfigKeys.BASE_URL, publishUrl);
}
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public final class ConfigKeys {
*/
public static final String PROXY_PORT = "proxy.port";

public static final String BASE_URL = "base.url";

public static final String LOGIN_TOKEN = "login.token.name";

public static final String WEBDRIVER_APPIUM_URL = "webdriver.appium.url";
Expand All @@ -46,14 +44,6 @@ public final class ConfigKeys {

public static final String WEBDRIVER_MOBILE = "webdriver.mobile";

public static final String WEBDRIVER_PROXY_COOKIE = "webdriver.secure.proxy.cookie";

public static final String WEBDRIVER_PROXY_COOKIE_NAME = "webdriver.secure.proxy.cookie_name";

public static final String WEBDRIVER_PROXY_COOKIE_VALUE = "webdriver.secure.proxy.cookie_value";

public static final String WEBDRIVER_PROXY_COOKIE_DOMAIN = "webdriver.secure.proxy.cookie_domain";

public static final String WEBDRIVER_REUSABLE = "webdriver.reusable";

public static final String WEBDRIVER_TYPE = "webdriver.type";
Expand All @@ -71,6 +61,8 @@ public final class ConfigKeys {
public static final String CONFIG_STRATEGY = "bobcat.config";
public static final String WEBDRIVER_PROP_PREFIX = "webdriver.";

public static final String COOKIE_LOAD_AUTOMATICALLY = "cookies.loadAutomatically";

private ConfigKeys() {
}
}
49 changes: 49 additions & 0 deletions bb-core/src/main/java/com/cognifide/qa/bb/cookies/Cookies.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*-
* #%L
* Bobcat
* %%
* Copyright (C) 2018 Cognifide Ltd.
* %%
* Licensed 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.
* #L%
*/
package com.cognifide.qa.bb.cookies;

import java.util.List;

import org.openqa.selenium.WebDriver;

import com.cognifide.qa.bb.cookies.domain.CookieData;
import com.google.inject.Inject;

public class Cookies {
public static final String FILE_NAME = "/cookies.yaml";

private List<CookieData> cookies;

@Inject
public Cookies(List<CookieData> cookies) {
this.cookies = cookies;
}

public void setCookies(WebDriver webDriver) {
cookies.forEach(cookie -> {
webDriver.get(cookie.getUrl());
webDriver.manage().addCookie(cookie.convertToSeleniumCookie());
});
}

public List<CookieData> getCookies() {
return cookies;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*-
* #%L
* Bobcat
* %%
* Copyright (C) 2018 Cognifide Ltd.
* %%
* Licensed 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.
* #L%
*/
package com.cognifide.qa.bb.cookies;

import java.util.List;

import com.cognifide.qa.bb.cookies.domain.CookieData;
import com.cognifide.qa.bb.cookies.modifier.CookiesModifier;
import com.cognifide.qa.bb.provider.selenium.webdriver.modifiers.webdriver.WebDriverModifier;
import com.google.inject.AbstractModule;
import com.google.inject.TypeLiteral;
import com.google.inject.multibindings.Multibinder;

public class CookiesModule extends AbstractModule {
@Override
public void configure() {
bind(new TypeLiteral<List<CookieData>>() {
}).toProvider(DefaultCookiesProvider.class);

Multibinder<WebDriverModifier> webDriverModifiers = Multibinder
.newSetBinder(binder(), WebDriverModifier.class);
webDriverModifiers.addBinding().to(CookiesModifier.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*-
* #%L
* Bobcat
* %%
* Copyright (C) 2018 Cognifide Ltd.
* %%
* Licensed 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.
* #L%
*/
package com.cognifide.qa.bb.cookies;

import static com.cognifide.qa.bb.cookies.Cookies.FILE_NAME;

import java.util.List;

import com.cognifide.qa.bb.cookies.domain.CookieData;
import com.cognifide.qa.bb.cookies.domain.CookiesData;
import com.cognifide.qa.bb.guice.ThreadScoped;
import com.cognifide.qa.bb.utils.YamlReader;
import com.google.inject.Provider;

@ThreadScoped
public class DefaultCookiesProvider implements Provider<List<CookieData>> {

private List<CookieData> cookiesData;

@Override
public List<CookieData> get() {
if (cookiesData == null) {
cookiesData = create();
}
return cookiesData;
}

private List<CookieData> create() {
return YamlReader.read(FILE_NAME, CookiesData.class).getCookies();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*-
* #%L
* Bobcat
* %%
* Copyright (C) 2018 Cognifide Ltd.
* %%
* Licensed 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.
* #L%
*/
package com.cognifide.qa.bb.cookies.domain;

import java.util.Date;

import org.openqa.selenium.Cookie;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;

public class CookieData {
private String name;

private String value;

private String path;

private String domain;

private Date expiry;

private boolean secure;

private boolean httpOnly;

@JsonCreator
public CookieData(
@JsonProperty("name") String name,
@JsonProperty("value") String value,
@JsonProperty("path") String path,
@JsonProperty("domain") String domain,
@JsonProperty("expiry")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd hh:mm:ss") Date expiry,
@JsonProperty("secure") boolean secure,
@JsonProperty("httpOnly") boolean httpOnly) {
this.name = name;
this.value = value;
this.path = path;
this.domain = domain;
this.expiry = expiry;
this.secure = secure;
this.httpOnly = httpOnly;
}

public String getUrl() {
return "http://" + domain;
}

public Cookie convertToSeleniumCookie() {
return new Cookie(name, value, domain, path, expiry, secure, httpOnly);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*-
* #%L
* Bobcat
* %%
* Copyright (C) 2018 Cognifide Ltd.
* %%
* Licensed 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.
* #L%
*/
package com.cognifide.qa.bb.cookies.domain;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonProperty;

public class CookiesData {
@JsonProperty
List<CookieData> cookies;

public List<CookieData> getCookies() {
return cookies;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*-
* #%L
* Bobcat
* %%
* Copyright (C) 2018 Cognifide Ltd.
* %%
* Licensed 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.
* #L%
*/
package com.cognifide.qa.bb.cookies.modifier;

import org.openqa.selenium.WebDriver;

import com.cognifide.qa.bb.constants.ConfigKeys;
import com.cognifide.qa.bb.cookies.Cookies;
import com.cognifide.qa.bb.provider.selenium.webdriver.modifiers.webdriver.WebDriverModifier;
import com.google.inject.Inject;
import com.google.inject.name.Named;

public class CookiesModifier implements WebDriverModifier {

@Inject
private Cookies cookies;

@Inject
@Named(ConfigKeys.COOKIE_LOAD_AUTOMATICALLY)
private boolean loadAutomaticallyProperty;

@Override
public boolean shouldModify() {
return loadAutomaticallyProperty && (getClass().getResource(Cookies.FILE_NAME) != null);
}

@Override
public WebDriver modify(WebDriver webDriver) {
cookies.setCookies(webDriver);
return webDriver;
}
}
Loading