Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Changes re code review
Reorder password so "required chars" not at beginning More default symbols yaml test concatenate all characters to use as available characters once required chars added Minor other changes
- Loading branch information
Showing
6 changed files
with
126 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,67 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
package org.apache.brooklyn.camp.brooklyn.policy; | ||
|
||
import org.apache.brooklyn.api.entity.Entity; | ||
import org.apache.brooklyn.api.sensor.AttributeSensor; | ||
import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest; | ||
import org.apache.brooklyn.core.entity.Entities; | ||
import org.apache.brooklyn.core.sensor.Sensors; | ||
import org.apache.brooklyn.entity.software.base.EmptySoftwareProcess; | ||
import org.apache.brooklyn.test.Asserts; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testng.annotations.Test; | ||
|
||
import com.google.common.collect.Iterables; | ||
|
||
public class CreatePasswordSensorIntegrationTest extends AbstractYamlTest { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(CreatePasswordSensorIntegrationTest.class); | ||
AttributeSensor<String> PASSWORD_1 = Sensors.newStringSensor("test.password.1", "Host name as known internally in " + | ||
"the subnet where it is running (if different to host.name)"); | ||
AttributeSensor<String> PASSWORD_2 = Sensors.newStringSensor("test.password.2", "Host name as known internally in " + | ||
"the subnet where it is running (if different to host.name)"); | ||
|
||
@Test(groups = "Integration") | ||
public void testProvisioningProperties() throws Exception { | ||
final Entity app = createAndStartApplication(loadYaml("EmptySoftwareProcessWithPassword.yaml")); | ||
|
||
waitForApplicationTasks(app); | ||
EmptySoftwareProcess entity = Iterables.getOnlyElement(Entities.descendants(app, EmptySoftwareProcess.class)); | ||
|
||
assertPasswordLength(entity, PASSWORD_1, 15); | ||
|
||
assertPasswordOnlyContains(entity, PASSWORD_2, "abc"); | ||
|
||
} | ||
|
||
private void assertPasswordOnlyContains(EmptySoftwareProcess entity, AttributeSensor<String> password, String acceptableChars) { | ||
String attribute_2 = entity.getAttribute(password); | ||
for (char c : attribute_2.toCharArray()) { | ||
Asserts.assertTrue(acceptableChars.indexOf(c) != -1); | ||
} | ||
} | ||
|
||
private void assertPasswordLength(EmptySoftwareProcess entity, AttributeSensor<String> password, int expectedLength) { | ||
String attribute_1 = entity.getAttribute(password); | ||
Asserts.assertEquals(attribute_1.length(), expectedLength); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,17 @@ | ||
name: example-with-CreatePasswordSensor | ||
description: | | ||
Creates an emptyService and then attaches a password to it | ||
origin: https://github.com/apache/incubator-brooklyn | ||
location: localhost | ||
services: | ||
- type: org.apache.brooklyn.entity.software.base.EmptySoftwareProcess | ||
brooklyn.initializers: | ||
- type: org.apache.brooklyn.core.sensor.password.CreatePasswordSensor | ||
brooklyn.config: | ||
name: test.password.1 | ||
password.length: 15 | ||
- type: org.apache.brooklyn.core.sensor.password.CreatePasswordSensor | ||
brooklyn.config: | ||
name: test.password.2 | ||
password.chars: abc | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters