001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.maven.scm; 020 021import org.junit.Test; 022 023import static org.junit.Assert.assertNotSame; 024import static org.junit.Assert.assertTrue; 025 026public class ScmResultTest { 027 028 private static final String PASSWORD = "secr$t"; 029 030 private static final String SCM_URL_GIT_COLON = 031 "scm:git:https://username:" + PASSWORD + "@github.com/username/repo.git"; 032 033 private static final String MOCK_ERROR_OUTPUT = "fatal: repository '" + SCM_URL_GIT_COLON + "' not found"; 034 035 private static final String MOCK_ERROR_MULTILINE_OUTPUT = "remote: Invalid username or password." 036 + System.lineSeparator() + "fatal: Authentication failed for '" + SCM_URL_GIT_COLON + "'"; 037 038 @Test 039 public void testPasswordsAreMaskedInOutput() throws Exception { 040 ScmResult result = new ScmResult("git push", "git-push failed", MOCK_ERROR_OUTPUT, false); 041 assertNotSame("Command output contains password", MOCK_ERROR_OUTPUT, result.getCommandOutput()); 042 assertTrue("Command output not masked", result.getCommandOutput().contains(ScmResult.PASSWORD_PLACE_HOLDER)); 043 044 result = new ScmResult("git push", "git-push failed", MOCK_ERROR_MULTILINE_OUTPUT, false); 045 assertNotSame("Command output contains password", MOCK_ERROR_MULTILINE_OUTPUT, result.getCommandOutput()); 046 assertTrue("Command output not masked", result.getCommandOutput().contains(ScmResult.PASSWORD_PLACE_HOLDER)); 047 } 048}