Skip to content

Commit

Permalink
Add checks for removal of intermediate secret when SB is removed (#957)
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Macík <pavel.macik@gmail.com>
  • Loading branch information
pmacik committed Apr 27, 2021
1 parent 7e3c8fd commit c256ac6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
14 changes: 12 additions & 2 deletions test/acceptance/features/steps/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def then_app_is_connected_to_db(context, db_name):
@when(u'Service binding "{sb_name}" is deleted')
def service_binding_is_deleted(context, sb_name):
openshift = Openshift()
context.sb_secret = get_sbr_secret_name(context, sb_name)
openshift.delete_service_binding(sb_name, context.namespace.name)


Expand Down Expand Up @@ -257,6 +258,14 @@ def sbo_is_ready(context, sbr_name):
sbo_jq_is(context, '.status.conditions[] | select(.type=="CollectionReady").status', sbr_name, 'True')
sbo_jq_is(context, '.status.conditions[] | select(.type=="InjectionReady").status', sbr_name, 'True')
sbo_jq_is(context, '.status.conditions[] | select(.type=="Ready").status', sbr_name, 'True')
context.sb_secret = get_sbr_secret_name(context, sbr_name)


@step(u'Service Binding secret is not present')
def sb_secret_is_not_present(context):
openshift = Openshift()
polling2.poll(lambda: openshift.search_resource_in_namespace("secrets", context.sb_secret, context.namespace.name),
step=100, timeout=1000, ignore_exceptions=(ValueError,), check_success=lambda v: v is None)


@given(u'Openshift Serverless Operator is running')
Expand Down Expand Up @@ -304,9 +313,10 @@ def quarkus_app_is_imported_as_knative_service(context, application_name):
context.application_type = "knative"


def get_sbr_secret_name(context):
def get_sbr_secret_name(context, sbr_name=None):
openshift = Openshift()
output = openshift.get_resource_info_by_jsonpath("servicebindings", context.sbr_name, context.namespace.name, "{.status.secret}")
output = openshift.get_resource_info_by_jsonpath(
"servicebindings", context.sbr_name if sbr_name is None else sbr_name, context.namespace.name, "{.status.secret}")
assert output is not None, "Failed to fetch secret name from ServiceBinding"
return output

Expand Down
43 changes: 21 additions & 22 deletions test/acceptance/features/unbindAppToService.feature
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ Feature: Unbind an application from a service
name: example-backend
id: backend
"""
* Service Binding "binding-request-a-d-u" is ready
* The application env var "BACKEND_HOST" has value "example.com"
* The application env var "BACKEND_USERNAME" has value "foo"

When Service binding "binding-request-a-d-u" is deleted

Then The env var "BACKEND_HOST" is not available to the application
And The env var "BACKEND_USERNAME" is not available to the application

* The env var "BACKEND_USERNAME" is not available to the application
* Service Binding secret is not present

Scenario: Unbind a generic test application from the backing service when the backing service has been deleted
Given The Custom Resource is present
Expand Down Expand Up @@ -87,26 +86,26 @@ Feature: Unbind an application from a service
name: example-backend
id: backend
"""
* Service Binding "binding-request-a-d-u" is ready
* The application env var "BACKEND_HOST" has value "example.com"
* The application env var "BACKEND_USERNAME" has value "foo"

When BackingService is deleted
"""
apiVersion: "stable.example.com/v1"
kind: Backend
metadata:
name: example-backend
annotations:
service.binding/host: path={.spec.host}
service.binding/username: path={.spec.username}
spec:
host: example.com
username: foo
"""
* BackingService is deleted
"""
apiVersion: "stable.example.com/v1"
kind: Backend
metadata:
name: example-backend
annotations:
service.binding/host: path={.spec.host}
service.binding/username: path={.spec.username}
spec:
host: example.com
username: foo
"""
When Service binding "binding-request-a-d-u" is deleted

Then The env var "BACKEND_HOST" is not available to the application
And The env var "BACKEND_USERNAME" is not available to the application
* The env var "BACKEND_USERNAME" is not available to the application
* Service Binding secret is not present

Scenario: Remove bindings projected as files from generic test application
Given Generic test application "remove-bindings-as-files-app" is running
Expand Down Expand Up @@ -143,7 +142,6 @@ Feature: Unbind an application from a service
resource: deployments
"""
* Service Binding "remove-bindings-as-files-app-sb" is ready

* Content of file "/bindings/remove-bindings-as-files-app-sb/host" in application pod is
"""
example.common
Expand All @@ -155,4 +153,5 @@ Feature: Unbind an application from a service
When Service Binding "remove-bindings-as-files-app-sb" is deleted
Then The application got redeployed 2 times so far
* File "/bindings/remove-bindings-as-files-app-sb/host" is unavailable in application pod
* File "/bindings/remove-bindings-as-files-app-sb/port" is unavailable in application pod
* File "/bindings/remove-bindings-as-files-app-sb/port" is unavailable in application pod
* Service Binding secret is not present

0 comments on commit c256ac6

Please sign in to comment.