Skip to content

Commit

Permalink
Add binding expiration tests to SKR tests (#1261)
Browse files Browse the repository at this point in the history
* Add binding expiration tests to SKR tests

* Test

* Pass

* Fail

* Fail

* Error handling

* Change message

* Next test

* Test

* Logs

* Refactor

* Better expect

* Increase timeout

* Change assertion

* Tiemout

* Timeout

* Increase timeout

* More test

* Change expiration

* Test

* Test

* Test

* Tiemouts

* Tiemouts

* Refactor

* Refactor

* Reject

* Import chai

* Change test

* Change logs

* Change call

* Change call

* Test alternative

* Test alternative

* Test alternative

* Test alternative

* Test alternative

* Test alternative

* Fail test

* Expect fail

* Expect fail

* Error repsonse

* Logs

* Logs

* Change fail

* Change fail

* Add asert

* Change to done

* Fix client

* Fix bug

* Expect

* Dont log

* Dont log

* Test

* Fix test

* Prepare second test

* Better timeouts

* Better timeouts

* Full test

* Full test

* Fix function

* Add missing return

* Fix access

* Lint fix

* Fix

* Disable leaks check

* To const
  • Loading branch information
MarekMichali authored Oct 8, 2024
1 parent 57b2c76 commit 67f1dfd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
6 changes: 4 additions & 2 deletions testing/e2e/skr/kyma-environment-broker/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,12 @@ class KEBClient {
};
const bindingID = Math.random().toString(36).substring(2, 18);
const endpoint = `service_instances/${instanceID}/service_bindings/${bindingID}?accepts_incomplete=true`;
const config = await this.buildRequest(payload, endpoint, 'put');

try {
return await this.callKEB(payload, endpoint, 'put');
return await axios.request(config);
} catch (err) {
throw new Error(`error while creating binding: ${err.toString()}`);
throw err;
}
}

Expand Down
46 changes: 41 additions & 5 deletions testing/e2e/skr/skr-binding-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ describe('SKR Binding test', function() {

it('Create SKR binding for service account using Kubernetes TokenRequest', async function() {
try {
kubeconfigFromBinding = await keb.createBinding(options.instanceID, true);
const resp = await keb.createBinding(options.instanceID, true);
kubeconfigFromBinding = resp.data.credentials.kubeconfig;
} catch (err) {
console.log(err);
}
});

it('Initiate K8s client with kubeconfig from binding', async function() {
await initializeK8sClient({kubeconfig: kubeconfigFromBinding.credentials.kubeconfig});
await initializeK8sClient({kubeconfig: kubeconfigFromBinding});
});

it('Fetch sap-btp-manager secret using binding for service account from Kubernetes TokenRequest', async function() {
Expand All @@ -47,21 +48,56 @@ describe('SKR Binding test', function() {
it('Create SKR binding using Gardener', async function() {
const expirationSeconds = 900;
try {
kubeconfigFromBinding = await keb.createBinding(options.instanceID, false, expirationSeconds);
expect(getKubeconfigValidityInSeconds(kubeconfigFromBinding.credentials.kubeconfig)).to.equal(expirationSeconds);
const resp = await keb.createBinding(options.instanceID, false, expirationSeconds);
kubeconfigFromBinding = resp.data.credentials.kubeconfig;
expect(getKubeconfigValidityInSeconds(kubeconfigFromBinding)).to.equal(expirationSeconds);
} catch (err) {
console.log(err);
}
});

it('Initiate K8s client with kubeconfig from binding', async function() {
await initializeK8sClient({kubeconfig: kubeconfigFromBinding.credentials.kubeconfig});
await initializeK8sClient({kubeconfig: kubeconfigFromBinding});
});

it('Fetch sap-btp-manager secret using binding from Gardener', async function() {
await getSecret(secretName, ns);
});

it('Should not allow creation of SKR binding when expiration seconds value is below the min value', async function() {
const expirationSeconds = 1;
try {
await keb.createBinding(options.instanceID, true, expirationSeconds);
expect.fail('The call was expected to fail but it passed');
} catch (err) {
if (err.response) {
expect(err.response.status).equal(400);
expect(err.response.data.description).to.include('expiration_seconds cannot be less than');
console.log('Got response:');
console.log(err.response.data);
} else {
throw err;
}
}
});

it('Should not allow creation of SKR binding when expiration seconds value is over the max value', async function() {
const expirationSeconds = 999999999;
try {
await keb.createBinding(options.instanceID, true, expirationSeconds);
expect.fail('The call was expected to fail but it passed');
} catch (err) {
if (err.response) {
expect(err.response.status).equal(400);
expect(err.response.data.description).to.include('expiration_seconds cannot be greater than');
console.log('Got response:');
console.log(err.response.data);
} else {
throw err;
}
}
});

after('Cleanup the resources', async function() {
this.timeout(deprovisioningTimeout);
if (process.env['SKIP_DEPROVISIONING'] != 'true') {
Expand Down

0 comments on commit 67f1dfd

Please sign in to comment.