Skip to content
Snippets Groups Projects

Invalidate stored service password if the endpoint URL is changed

Closed Valery Sizov requested to merge update_passwd_service into master

This MR handles bugs (introduced by !1558 (merged)):

  • It is not possible to set a new URL and a password at the same time (new password is ignored)
  • An error occurs on the Service Templates admin pages (prop_updated? was referencing the service's project, which is not defined for templates)
  • Passwords are reset on every save in Service Templates admin pages

Related !1583 (merged)

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
120 125 # ActiveRecord does not provide a mechanism to track changes in serialized keys.
121 126 # This is why we need to perform extra query to do it mannually.
122 127 def prop_updated?(prop_name)
123 relation_name = self.type.underscore
124 previous_value = project.send(relation_name).send(prop_name)
125 return false if previous_value.nil?
126 previous_value != send(prop_name)
128 return false if send("#{prop_name}_was").nil?
129 send("#{prop_name}_was") != send(prop_name)
  • @vsizov One note to address or ignore, your call. Otherwise, LGTM.

    Edited by Robert Speicher
  • Hi,

    I believe this would fail the following scenarios:

        it "does not reset password if new url is set together with password, even if it's the same password" do
          @teamcity_service.teamcity_url = 'http://gitlab_edited.com'
          @teamcity_service.password = 'password'
          @teamcity_service.save
          expect(@teamcity_service.password).to eq("password")
          expect(@teamcity_service.teamcity_url).to eq("http://gitlab_edited.com")
        end
    
    
        context "when no password was set before" do
          before do
            @teamcity_service = TeamcityService.create(
              project: create(:project),
              properties: {
                teamcity_url: 'http://gitlab.com',
                username: 'mic'
              }
            )
          end
    
          it "saves password if new url is set together with password" do
            @teamcity_service.teamcity_url = 'http://gitlab_edited.com'
            @teamcity_service.password = 'password'
            @teamcity_service.save
            expect(@teamcity_service.password).to eq("password")
            expect(@teamcity_service.teamcity_url).to eq("http://gitlab_edited.com")
          end
        end
    
        it "should reset password if url changed, even if setter called multiple times" do
          @teamcity_service.teamcity_url = 'http://gitlab1.com'
          @teamcity_service.teamcity_url = 'http://gitlab1.com'
          @teamcity_service.save
          expect(@teamcity_service.password).to be_nil
        end
  • @cernvcs You're right, all three of those fail.

    @vsizov Please address.

  • mentioned in merge request !1600 (merged)

  • Valery Sizov Status changed to closed

    Status changed to closed

  • Valery Sizov mentioned in commit 62bf2eb8

    mentioned in commit 62bf2eb8

  • Please register or sign in to reply
    Loading