Merge branch 'fix/reassign-secret-token-on-generate' into 'master'

Reassign secret token when regenerating one

## What does this MR do?

This is an attempt to fix intermittent errors in out test suite.

```text
Failures:

  1) Gitlab::Shell memoized secret_token creates and links the secret token file
     Failure/Error: expect(File.read(secret_file).chomp).to eq(secret_token)
     
       expected: "690f959e206ab91acc54e1c605c7ff90"
            got: "cccb4e8df9360600271e61114d4e6e68"
     
       (compared using ==)
     # ./spec/lib/gitlab/backend/shell_spec.rb:47:in `block (3 levels) in <top (required)>'
```

It appears that `spec/lib/gitlab/backend/shell_spec.rb` tries to change the file that stores secret token, but `Gitlab::Shell` memoizes `@secret_token` on class level, so when it was already created by other tests (`spec/requests/api/internal_spec.rb` in this case), memoized token is not reassigned even if it was generated again with `ensure_secret_token!`.

See merge request !6844
This commit is contained in:
Douwe Maan 2016-10-14 10:57:18 +00:00
commit 2a0cccc13e

View file

@ -47,8 +47,8 @@ module Gitlab
unless File.size?(secret_file) unless File.size?(secret_file)
# Generate a new token of 16 random hexadecimal characters and store it in secret_file. # Generate a new token of 16 random hexadecimal characters and store it in secret_file.
token = SecureRandom.hex(16) @secret_token = SecureRandom.hex(16)
File.write(secret_file, token) File.write(secret_file, @secret_token)
end end
link_path = File.join(shell_path, '.gitlab_shell_secret') link_path = File.join(shell_path, '.gitlab_shell_secret')