|
98 | 98 | end |
99 | 99 | end |
100 | 100 |
|
| 101 | + describe "#copy_to" do |
| 102 | + let(:revision) { "abc123" } |
| 103 | + let(:destination) { tmp("git-proxy-copy") } |
| 104 | + |
| 105 | + before do |
| 106 | + # The bare cache (`path`) is the clone source, so stub it away and only |
| 107 | + # exercise the post-clone wiring of the working copy at `destination`. |
| 108 | + allow(File).to receive(:stat).and_call_original |
| 109 | + allow(File).to receive(:stat).with(destination).and_return(double("File::Stat", mode: 0o755)) |
| 110 | + allow(File).to receive(:chmod) |
| 111 | + allow(git_proxy).to receive(:capture).and_return(["", "", clone_result]) |
| 112 | + end |
| 113 | + |
| 114 | + it "points the working copy's origin back at the real remote" do |
| 115 | + expect(git_proxy).to receive(:capture).with(["remote", "set-url", "origin", uri], destination).and_return(["", "", clone_result]) |
| 116 | + git_proxy.copy_to(destination) |
| 117 | + end |
| 118 | + |
| 119 | + it "does not persist credentials in the working copy's origin" do |
| 120 | + Bundler.settings.temporary(uri => "u:p") do |
| 121 | + credentialed_uri = "https://u:p@github.com/ruby/rubygems.git" |
| 122 | + expect(git_proxy).not_to receive(:capture).with(["remote", "set-url", "origin", credentialed_uri], destination) |
| 123 | + expect(git_proxy).to receive(:capture).with(["remote", "set-url", "origin", uri], destination).and_return(["", "", clone_result]) |
| 124 | + git_proxy.copy_to(destination) |
| 125 | + end |
| 126 | + end |
| 127 | + |
| 128 | + context "when the remote URI embeds credentials" do |
| 129 | + let(:uri) { "https://user:secret@github.com/ruby/rubygems.git" } |
| 130 | + |
| 131 | + it "strips the password before writing origin" do |
| 132 | + filtered_uri = "https://user@github.com/ruby/rubygems.git" |
| 133 | + expect(git_proxy).not_to receive(:capture).with(["remote", "set-url", "origin", uri], destination) |
| 134 | + expect(git_proxy).to receive(:capture).with(["remote", "set-url", "origin", filtered_uri], destination).and_return(["", "", clone_result]) |
| 135 | + git_proxy.copy_to(destination) |
| 136 | + end |
| 137 | + end |
| 138 | + end |
| 139 | + |
101 | 140 | describe "#version" do |
102 | 141 | context "with a normal version number" do |
103 | 142 | before do |
|
0 commit comments