Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GET and DELETE in Kyma Binding SKR test #1249

28 changes: 25 additions & 3 deletions testing/e2e/skr/kyma-environment-broker/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class KEBClient {
});
}

async createBinding(instanceID, serviceAccount, expirationSeconds = DEFAULT_EXPIRATION_SECONDS) {
async createBinding(instanceID, bindingID, serviceAccount, expirationSeconds = DEFAULT_EXPIRATION_SECONDS) {
const payload = {
service_id: KYMA_SERVICE_ID,
plan_id: this.planID,
Expand All @@ -282,8 +282,7 @@ class KEBClient {
expiration_seconds: expirationSeconds,
},
};
const bindingID = Math.random().toString(36).substring(2, 18);
const endpoint = `service_instances/${instanceID}/service_bindings/${bindingID}?accepts_incomplete=true`;
const endpoint = `service_instances/${instanceID}/service_bindings/${bindingID}?accepts_incomplete=false`;
const config = await this.buildRequest(payload, endpoint, 'put');

try {
Expand All @@ -293,6 +292,29 @@ class KEBClient {
}
}

async deleteBinding(instanceID, bindingID) {
const endpoint = `service_instances/${instanceID}/service_bindings/${bindingID}
?accepts_incomplete=false&service_id=${KYMA_SERVICE_ID}&plan_id=${this.planID}`;
const config = await this.buildRequest({}, endpoint, 'delete');

try {
return await axios.request(config);
} catch (err) {
throw err;
}
}

async getBinding(instanceID, bindingID) {
const endpoint = `service_instances/${instanceID}/service_bindings/${bindingID}?accepts_incomplete=false`;
const config = await this.buildRequest({}, endpoint, 'get');

try {
return await axios.request(config);
} catch (err) {
throw err;
}
}

getPlatformRegion() {
if (this.platformRegion && this.platformRegion != '') {
return `${this.platformRegion}/`;
Expand Down
74 changes: 69 additions & 5 deletions testing/e2e/skr/skr-binding-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ describe('SKR Binding test', function() {

const options = gatherOptions(); // with default values
let kubeconfigFromBinding;
let bindingID;

before('Ensure SKR is provisioned', async function() {
this.timeout(provisioningTimeout);
await provisionSKRInstance(options, provisioningTimeout);
});

it('Create SKR binding for service account using Kubernetes TokenRequest', async function() {
bindingID = Math.random().toString(36).substring(2, 18);
try {
const resp = await keb.createBinding(options.instanceID, true);
const resp = await keb.createBinding(options.instanceID, bindingID, true);
kubeconfigFromBinding = resp.data.credentials.kubeconfig;
} catch (err) {
console.log(err);
Expand All @@ -45,15 +47,48 @@ describe('SKR Binding test', function() {
await getSecret(secretName, ns);
});

it('Fetch SKR binding created using Kubernetes TokenRequest', async function() {
const resp = await keb.getBinding(options.instanceID, bindingID);
expect(resp.data.credentials.kubeconfig).to.equal(kubeconfigFromBinding);
});

it('Delete SKR binding created using Kubernetes TokenRequest', async function() {
const resp = await keb.deleteBinding(options.instanceID, bindingID);
expect(resp.status).equal(200);

try {
await keb.getBinding(options.instanceID, bindingID);
expect.fail('The call was expected to fail but it passed');
} catch (err) {
if (err.response) {
expect(err.response.status).equal(404);
console.log('Got response:');
console.log(err.response.data);
} else {
throw err;
}
}
});

it('Should not allow to fetch sap-btp-manager secret using binding from Kubernetes TokenRequest', async function() {
try {
await getSecret(secretName, ns);
expect.fail('The call was expected to fail but it passed');
} catch (err) {
expect(err.message).to.include('You must be logged in to the server');
}
});

it('Create SKR binding using Gardener', async function() {
bindingID = Math.random().toString(36).substring(2, 18);
const expirationSeconds = 900;
try {
const resp = await keb.createBinding(options.instanceID, false, expirationSeconds);
const resp = await keb.createBinding(options.instanceID, bindingID, false, expirationSeconds);
kubeconfigFromBinding = resp.data.credentials.kubeconfig;
expect(getKubeconfigValidityInSeconds(kubeconfigFromBinding)).to.equal(expirationSeconds);
} catch (err) {
console.log(err);
}
expect(getKubeconfigValidityInSeconds(kubeconfigFromBinding)).to.equal(expirationSeconds);
});

it('Initiate K8s client with kubeconfig from binding', async function() {
Expand All @@ -64,10 +99,38 @@ describe('SKR Binding test', function() {
await getSecret(secretName, ns);
});

it('Fetch SKR binding created using Gardener', async function() {
const resp = await keb.getBinding(options.instanceID, bindingID);
expect(resp.data.credentials.kubeconfig).to.equal(kubeconfigFromBinding);
});

it('Delete SKR binding created using Gardener', async function() {
const resp = await keb.deleteBinding(options.instanceID, bindingID);
expect(resp.status).equal(200);

try {
await keb.getBinding(options.instanceID, bindingID);
expect.fail('The call was expected to fail but it passed');
} catch (err) {
if (err.response) {
expect(err.response.status).equal(404);
console.log('Got response:');
console.log(err.response.data);
} else {
throw err;
}
}
});

it('Try to fetch sap-btp-manager secret using binding from Gardener', async function() {
ralikio marked this conversation as resolved.
Show resolved Hide resolved
await getSecret(secretName, ns);
});

it('Should not allow creation of SKR binding when expiration seconds value is below the min value', async function() {
bindingID = Math.random().toString(36).substring(2, 18);
const expirationSeconds = 1;
try {
await keb.createBinding(options.instanceID, true, expirationSeconds);
await keb.createBinding(options.instanceID, bindingID, true, expirationSeconds);
expect.fail('The call was expected to fail but it passed');
} catch (err) {
if (err.response) {
Expand All @@ -82,9 +145,10 @@ describe('SKR Binding test', function() {
});

it('Should not allow creation of SKR binding when expiration seconds value is over the max value', async function() {
bindingID = Math.random().toString(36).substring(2, 18);
const expirationSeconds = 999999999;
try {
await keb.createBinding(options.instanceID, true, expirationSeconds);
await keb.createBinding(options.instanceID, bindingID, true, expirationSeconds);
expect.fail('The call was expected to fail but it passed');
} catch (err) {
if (err.response) {
Expand Down
Loading