Re: pax exam tests started failing when I bumped karaf version to 4.3.2

2021-05-23 Thread Eric Lilja
Hi Steinar, for my Pax Exam Karaf tests, I am using a builder-style class I
wrote called KarafConfigurator for building the list of configuration
options.

It has methods for replacing bundled config files with user
supplied versions. Here's an example using startup.properties:

public KarafConfigurator replaceStartupProperties(final URL
newStartupProperties) throws URISyntaxException {
return replaceConfigurationFile(STARTUP_PROPERTIES_FILE_PATH,
newStartupProperties);
}

public KarafConfigurator replaceConfigurationFile(final String path, final
URL newConfigurationFileUrl) throws URISyntaxException {
final File newConfigurationFile = new
File(newConfigurationFileUrl.toURI());

return replaceConfigurationFile(path, newConfigurationFile);
}

public KarafConfigurator replaceConfigurationFile(final String path, final
File newConfigurationFile) {
final Option optionReplaceConfFile =
KarafDistributionOption.replaceConfigurationFile(path,
newConfigurationFile);

options.add(optionReplaceConfFile);

return this;
}

STARTUP_PROPERTIES_FILE_PATH denotes the path inside the Karaf distro to
the startup.properties-file. It's defined as:

private static final String STARTUP_PROPERTIES_FILE_PATH =
"etc/startup.properties";

Notice it's doesn't start with "/"

The user of KarafConfigurator-class would simply call the
replaceStartupProperties()-method. A URL to a replacement-file in
src/test/resources can be obtained simply:

final Class clz = getClass();
final URL resourceUrl = clz.getResource("/startup.properties");

Here it's assumed the file is the user wants to use as a replacement is
called "startup.properties" and is located in src/test/resources (assuming
Maven)

- Eric L

On Sun, May 23, 2021 at 11:42 AM Steinar Bang  wrote:

> > Steinar Bang :
>
> >> A simple workaround is to include your own users.properties in the
> pax-exam option.
>
> > Thanks! I will look into this.
>
> I tried this:
> @Configuration
> public Option[] config() {
> final MavenArtifactUrlReference authserviceFeatureRepo = maven()
> .groupId("no.priv.bang.authservice")
> .artifactId("karaf")
> .version("LATEST")
> .type("xml")
> .classifier("features");
> File dummyUsersProperties = new
> File(getClass().getClassLoader().getResource("dummy.users.properties").getFile());
> Option[] options = new Option[] {
> features(authserviceFeatureRepo),
> replaceConfigurationFile("/etc/users.properties",
> dummyUsersProperties)
> };
> return Stream.of(super.config(),
> options).flatMap(Stream::of).toArray(Option[]::new);
> }
>
> But the test still fails almost immediately with
>  org.ops4j.pax.exam.TestContainerException: java.lang.RuntimeException:
> Config resource /etc/users.properties not found
>
> I've tried "users.properties" and "etc/users.properties" as the
> configurationFilePath argument to replaceConfigurationFile(), but it
> didn't make any difference.
>
>


Re: pax exam tests started failing when I bumped karaf version to 4.3.2

2021-05-23 Thread Steinar Bang
> Steinar Bang :

>> A simple workaround is to include your own users.properties in the pax-exam 
>> option.

> Thanks! I will look into this.

I tried this:
@Configuration
public Option[] config() {
final MavenArtifactUrlReference authserviceFeatureRepo = maven()
.groupId("no.priv.bang.authservice")
.artifactId("karaf")
.version("LATEST")
.type("xml")
.classifier("features");
File dummyUsersProperties = new 
File(getClass().getClassLoader().getResource("dummy.users.properties").getFile());
Option[] options = new Option[] {
features(authserviceFeatureRepo),
replaceConfigurationFile("/etc/users.properties", 
dummyUsersProperties)
};
return Stream.of(super.config(), 
options).flatMap(Stream::of).toArray(Option[]::new);
}

But the test still fails almost immediately with
 org.ops4j.pax.exam.TestContainerException: java.lang.RuntimeException: Config 
resource /etc/users.properties not found

I've tried "users.properties" and "etc/users.properties" as the
configurationFilePath argument to replaceConfigurationFile(), but it
didn't make any difference.



Re: pax exam tests started failing when I bumped karaf version to 4.3.2

2021-05-23 Thread Steinar Bang
> Jean-Baptiste Onofre :

> Hi,
> It’s has been discussed on the mailing list already (I don’t remember who 
> reported this).

> The change we did is that etc/users.properties has the karaf user commented 
> now (for security reason).

Right. I noticed yesterday, when rolling the .deb package for karaf 4.3.2. :-)
 
https://steinar.bang.priv.no/2018/01/23/installing-apache-karaf-on-debian/#comment-15646

I don't know if I have any users for the .deb, besides myself, but just
in case, I guess I should make a note about the ssh change...?

A side note on this: the .deb locks down the /etc/karaf directory
because of the username/password thing (no public read access and owned
by user karaf, group karaf)

> However, etc/users.properties is still part of the karaf distribution. But, 
> as it contains only comments now, I suspect pax-exam-karaf to not include it 
> in the core distribution run. Karaf itests use it, so, it should be minor.

Yes, I suspected it was releated to the commenting out in some way.

> A simple workaround is to include your own users.properties in the pax-exam 
> option.

Thanks! I will look into this.

> I will check and create Jira for 4.3.3.

Thanks!

One note on the ssh thing: is there a Jira on being able to use ssh keys
instead of username/password in the karaf ssh?

If not, should I make one?