it("should prompt user to accept self-signed certificate", function(done) {
      var hostModel = {
        address: "my-docker.com",
        placementZone: {documentSelfLink: "somePlacementZoneRef"},
        credential: {documentSelfLink: "someCredentialRef"},
        connectionType: "someConnectionType",
        customProperties: []
      };

      var CERT = "-----BEGIN CERTIFICATE-----"; // for testing purposes, not a real PEM certificate.
      var certificateHolder = {
        commonName: "my-docker.com",
        issuerName: "my-docker.com",
        certificate: CERT
      };

      spyOn(services, 'addHost').and.callFake(function(params) {
        return new Promise(function(resolve, reject){
          resolve(certificateHolder);
        });
      });

      waitForData((data) => {
        return !!data.hostAddView.shouldAcceptCertificate;
      }).then(function(data) {
        var shouldAcceptCertificate = data.hostAddView.shouldAcceptCertificate;
        expect(shouldAcceptCertificate).toBeDefined();
        expect(shouldAcceptCertificate).not.toBe(null);

        expect(shouldAcceptCertificate.certificateHolder).toEqual(certificateHolder);
      }).then(done);

      HostActions.addHost(hostModel, []);
    });
    it("should give validation error on incorrect address", function(done) {
      var incorrectAddressHostModel = {
        placementZone: {documentSelfLink: "somePlacementZoneRef"},
        credential: {documentSelfLink: "someCredentialRef"},
        connectionType: "someConnectionType"
      };

      waitForData().then(function(data) {
        var validationErrors = data.hostAddView.validationErrors;
        expect(validationErrors.address).toBe('errors.hostIp');
      }).then(function() {
        incorrectAddressHostModel.address = "incorrect address";

        var p = waitForData().then(function(data) {
          var validationErrors = data.hostAddView.validationErrors;
          expect(validationErrors.address).toBe('errors.hostIp');
        });

        HostActions.addHost(incorrectAddressHostModel, []);
        return p;
      }).then(function() {
        incorrectAddressHostModel.address = "addres:101010101";

        var p = waitForData().then(function(data) {
          var validationErrors = data.hostAddView.validationErrors;
          expect(validationErrors.address).toBe('errors.hostIp');
        });

        HostActions.addHost(incorrectAddressHostModel, []);
        return p;
      }).then(function() {
        incorrectAddressHostModel.address = "addres:101010101";

        var p = waitForData().then(function(data) {
          var validationErrors = data.hostAddView.validationErrors;
          expect(validationErrors.address).toBe('errors.hostIp');
        });

        HostActions.addHost(incorrectAddressHostModel, []);
        return p;
      }).then(function() {
        incorrectAddressHostModel.address = "httpsX://test.com";

        var p = waitForData().then(function(data) {
          var validationErrors = data.hostAddView.validationErrors;
          expect(validationErrors.address).toBe('errors.hostIp');
        });

        HostActions.addHost(incorrectAddressHostModel, []);
        return p;
      }).then(done);

      incorrectAddressHostModel.address = "incorrect,address";
      HostActions.addHost(incorrectAddressHostModel, []);
    });
Exemple #3
0
      .then(() => {
        // refresh hosts view
        actions.HostActions.openHosts();

        let validationErrors = {
          _valid: i18n.t('app.host.list.dataCollectEnd')
        };
        this.setInData(['validationErrors'], validationErrors);
        this.setInData(['dataCollectionEnd'], true);
        this.emitChange();
      })
      }).then(function() {
        incorrectAddressHostModel.address = "addres:101010101";

        var p = waitForData().then(function(data) {
          var validationErrors = data.hostAddView.validationErrors;
          expect(validationErrors.address).toBe('errors.hostIp');
        });

        HostActions.addHost(incorrectAddressHostModel, []);
        return p;
      }).then(function() {
    it("should add host when accept certificate", function(done) {
      var hostModel = {
        address: "my-docker.com",
        placementZone: {documentSelfLink: "somePlacementZoneRef"},
        credential: {documentSelfLink: "someCredentialRef"},
        descriptionLink: "someDescLink",
        connectionType: "API",
        customProperties: []
      };

      var CERT = "-----BEGIN CERTIFICATE-----"; // for testing purposes, not a real PEM certificate.
       var certificateHolder = {
        commonName: "my-docker.com",
        issuerName: "my-docker.com",
        certificate: CERT
      };

      spyOn(services, 'createCertificate').and.callFake(function(params) {
        return new Promise(function(resolve, reject){
          resolve();
        });
      });
      spyOn(services, 'addHost').and.callFake(function(params) {
        return new Promise(function(resolve, reject){
          resolve();
        });
      });

      var expectedDtoHost = {
        hostState: {
          id: hostModel.address,
          address: hostModel.address,
          resourcePoolLink: hostModel.resourcePoolLink,
          descriptionLink: "someDescLink",
          customProperties: {
            __authCredentialsLink: hostModel.credential.documentSelfLink,
            __adapterDockerType: hostModel.connectionType
          },
          powerState: hostModel.powerState,
          tagLinks: []
        },
        sslTrust: certificateHolder
      };

      testUtils.waitFor(function() {
        return services.createCertificate.calls.count() > 0 && services.addHost.calls.count() > 0;
      }).then(function() {
        expect(services.createCertificate).toHaveBeenCalledWith(certificateHolder);
        expect(services.addHost).toHaveBeenCalledWith(expectedDtoHost);
        done();
      });

      HostActions.acceptCertificateAndAddHost(certificateHolder, hostModel, []);
    });
    it("should give validation errors on empty fields", function(done) {
      var emptyHostModel = {
        address: "",
        placementZone: null,
        credential: null,
        connectionType: null
      };

      waitForData((data) => {
        return !!data.hostAddView.validationErrors;
      }).then(function(data) {
        var validationErrors = data.hostAddView.validationErrors;

        expect(validationErrors).toBeDefined();
        expect(validationErrors).not.toBe(null);

        expect(validationErrors.address).toBe('errors.required');
        expect(validationErrors.placementZone).toBe('errors.required');

        var onlyAddressEmptyHostModel = {
          address: "",
          placementZone: {documentSelfLink: "somePlacementZoneRef"},
          credential: {documentSelfLink: "someCredentialRef"},
          connectionType: "someConnectionType"
        };

        var p = waitForData();
        HostActions.addHost(onlyAddressEmptyHostModel, []);

        return p;
      }).then(function(data) {
        var validationErrors = data.hostAddView.validationErrors;

        expect(validationErrors).toBeDefined();
        expect(validationErrors).not.toBe(null);

        expect(validationErrors.address).toBe('errors.required');
        expect(validationErrors.placementZone).toBeUndefined();
        expect(validationErrors.credential).toBeUndefined();
        expect(validationErrors.connectionType).toBeUndefined();
      }).then(done);

      HostActions.addHost(emptyHostModel, []);
    });
    it("should NOT prompt user to accept known certificate and add host", function(done) {
      var hostModel = {
        address: "docker.com",
        placementZone: {documentSelfLink: "somePlacementZone"},
        credential: {documentSelfLink: "someCredentialRef"},
        descriptionLink: "someDescLink",
        connectionType: "API",
        customProperties: []
      };

      var expectedDtoHost = {
        hostState: {
          id: hostModel.address,
          address: hostModel.address,
          resourcePoolLink: hostModel.resourcePoolLink,
          descriptionLink: "someDescLink",
          customProperties: {
            __authCredentialsLink: hostModel.credential.documentSelfLink,
            __adapterDockerType: hostModel.connectionType
          },
          powerState: hostModel.powerState,
          tagLinks: []
        }
      };

      var addHostParams = null;
      spyOn(services, 'addHost').and.callFake(function(params) {
        return new Promise(function(resolve, reject){
          addHostParams = params;
          resolve();
        });
      });

      testUtils.waitFor(function() {
        return addHostParams != null;
      }).then(function() {
        expect(addHostParams).toEqual(expectedDtoHost);
        done();
      });

      HostActions.addHost(hostModel, []);
    });
      }).then(function(data) {
        var validationErrors = data.hostAddView.validationErrors;

        expect(validationErrors).toBeDefined();
        expect(validationErrors).not.toBe(null);

        expect(validationErrors.address).toBe('errors.required');
        expect(validationErrors.placementZone).toBe('errors.required');

        var onlyAddressEmptyHostModel = {
          address: "",
          placementZone: {documentSelfLink: "somePlacementZoneRef"},
          credential: {documentSelfLink: "someCredentialRef"},
          connectionType: "someConnectionType"
        };

        var p = waitForData();
        HostActions.addHost(onlyAddressEmptyHostModel, []);

        return p;
      }).then(function(data) {
 hostOperationSuccess: function() {
   actions.HostActions.operationCompleted();
 },
Exemple #10
0
 .then(() => {
   // refresh hosts view
   actions.HostActions.openHosts();
 });
Exemple #11
0
    enableHost: function(event) {
      event.preventDefault();

      HostActions.enableHost(this.model.selfLinkId);
    },