Return-Path: X-Original-To: apmail-hadoop-common-commits-archive@www.apache.org Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 37886D793 for ; Thu, 30 Aug 2012 02:35:37 +0000 (UTC) Received: (qmail 79119 invoked by uid 500); 30 Aug 2012 02:35:36 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 79069 invoked by uid 500); 30 Aug 2012 02:35:36 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-dev@hadoop.apache.org Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 79062 invoked by uid 99); 30 Aug 2012 02:35:36 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Aug 2012 02:35:36 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Aug 2012 02:35:32 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 390D42388994 for ; Thu, 30 Aug 2012 02:34:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1378794 - in /hadoop/common/branches/branch-1-win: ./ src/winutils/tests/ Date: Thu, 30 Aug 2012 02:34:47 -0000 To: common-commits@hadoop.apache.org From: acmurthy@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120830023448.390D42388994@eris.apache.org> Author: acmurthy Date: Thu Aug 30 02:34:47 2012 New Revision: 1378794 URL: http://svn.apache.org/viewvc?rev=1378794&view=rev Log: HADOOP-8453. Added unit tests for winutils. Contributed by Chuan Liu. Added: hadoop/common/branches/branch-1-win/src/winutils/tests/ hadoop/common/branches/branch-1-win/src/winutils/tests/test-all.bat hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-basics.bat hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-chmod.bat hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-chown.bat Modified: hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt hadoop/common/branches/branch-1-win/build.xml Modified: hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt?rev=1378794&r1=1378793&r2=1378794&view=diff ============================================================================== --- hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt (original) +++ hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt Thu Aug 30 02:34:47 2012 @@ -69,6 +69,8 @@ branch-hadoop-1-win - unreleased MAPREDUCE-4510. Fix needless check/logging of getconf in Windows. (Bikas Saha via acmurthy) + HADOOP-8453. Added unit tests for winutils. (Chuan Liu via acmurthy) + BUG FIXES HDFS-6527. Backport HADOOP-7389: Use of TestingGroups by tests causes Modified: hadoop/common/branches/branch-1-win/build.xml URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/build.xml?rev=1378794&r1=1378793&r2=1378794&view=diff ============================================================================== --- hadoop/common/branches/branch-1-win/build.xml (original) +++ hadoop/common/branches/branch-1-win/build.xml Thu Aug 30 02:34:47 2012 @@ -136,6 +136,8 @@ + + @@ -626,6 +628,16 @@ + + + + + + + + + + @@ -2175,6 +2187,20 @@ + + + + + + + + + + + + Added: hadoop/common/branches/branch-1-win/src/winutils/tests/test-all.bat URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/winutils/tests/test-all.bat?rev=1378794&view=auto ============================================================================== --- hadoop/common/branches/branch-1-win/src/winutils/tests/test-all.bat (added) +++ hadoop/common/branches/branch-1-win/src/winutils/tests/test-all.bat Thu Aug 30 02:34:47 2012 @@ -0,0 +1,19 @@ +:: Licensed to the Apache Software Foundation (ASF) under one or more +:: contributor license agreements. See the NOTICE file distributed with this +:: work for additional information regarding copyright ownership. The ASF +:: licenses this file to you under the Apache License, Version 2.0 (the +:: "License"); you may not use this file except in compliance with the License. +:: You may obtain a copy of the License at +:: +:: http://www.apache.org/licenses/LICENSE-2.0 +:: +:: Unless required by applicable law or agreed to in writing, software +:: distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +:: WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +:: License for the specific language governing permissions and limitations under +:: the License. +:: +@echo off +call test-winutils-basics +call test-winutils-chown +call test-winutils-chmod Added: hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-basics.bat URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-basics.bat?rev=1378794&view=auto ============================================================================== --- hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-basics.bat (added) +++ hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-basics.bat Thu Aug 30 02:34:47 2012 @@ -0,0 +1,95 @@ +:: Licensed to the Apache Software Foundation (ASF) under one or more +:: contributor license agreements. See the NOTICE file distributed with this +:: work for additional information regarding copyright ownership. The ASF +:: licenses this file to you under the Apache License, Version 2.0 (the +:: "License"); you may not use this file except in compliance with the License. +:: You may obtain a copy of the License at +:: +:: http://www.apache.org/licenses/LICENSE-2.0 +:: +:: Unless required by applicable law or agreed to in writing, software +:: distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +:: WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +:: License for the specific language governing permissions and limitations under +:: the License. +:: +@echo off +echo Test most basic security settings are working +setlocal +set WINUTILS="%HADOOP_HOME%\bin\winutils.exe" +set TESTDIR=winutils-test + +:: Setup test directory +:: +if not exist %TESTDIR% md %TESTDIR% +pushd %TESTDIR% + +:: Test cases +:: +echo Test case 1: +:: - Create a file. +:: - Change mode to 377 so owner does not have read permission. +:: - Verify the owner truly does not have the permissions to read. +if exist a goto Failure +type NUL>a +%WINUTILS% chmod 377 a +if not %ERRORLEVEL% == 0 goto Failure +type a +if %ERRORLEVEL% == 0 goto Failure +del a +if not %ERRORLEVEL% == 0 goto Failure +echo passed. + +echo Test case 2: +:: - Create a file. +:: - Change mode to 577 so owner does not have write permission. +:: - Verify the owner truly does not have the permissions to write. +if exist a goto Failure +type NUL>a +%WINUTILS% chmod 577 a +if not %ERRORLEVEL% == 0 goto Failure +cmd /C "echo a>>a" +if %ERRORLEVEL% == 0 goto Failure +del a +if not %ERRORLEVEL% == 0 goto Failure +echo passed. + +echo Test case 3: +:: - Copy WINUTILS to a new executable file, a.exe. +:: - Change mode to 677 so owner does not have execute permission. +:: - Verify the owner truly does not have the permissions to execute the file. +if exist a.exe goto Failure +copy %WINUTILS% a.exe >NUL +%WINUTILS% chmod 677 a.exe +if not %ERRORLEVEL% == 0 goto Failure +.\a.exe ls +if %ERRORLEVEL% == 0 goto Failure +del a.exe +if not %ERRORLEVEL% == 0 goto Failure +echo passed. + + +:: Cleanup +:: +popd +rd %TESTDIR% +goto Success + + +:: ----------------------------------------------------------------------------- +:: -- Function section starts below here +:: ----------------------------------------------------------------------------- + +:: Failure +:: - Report test failure +:: +:Failure +echo Test failed. +exit /B 1 + +:: Success +:: - Report test success +:: +:Success +echo Test succeeded. +exit /B 0 Added: hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-chmod.bat URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-chmod.bat?rev=1378794&view=auto ============================================================================== --- hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-chmod.bat (added) +++ hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-chmod.bat Thu Aug 30 02:34:47 2012 @@ -0,0 +1,174 @@ +:: Licensed to the Apache Software Foundation (ASF) under one or more +:: contributor license agreements. See the NOTICE file distributed with this +:: work for additional information regarding copyright ownership. The ASF +:: licenses this file to you under the Apache License, Version 2.0 (the +:: "License"); you may not use this file except in compliance with the License. +:: You may obtain a copy of the License at +:: +:: http://www.apache.org/licenses/LICENSE-2.0 +:: +:: Unless required by applicable law or agreed to in writing, software +:: distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +:: WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +:: License for the specific language governing permissions and limitations under +:: the License. +:: +@echo off +echo Test various chmod operations +setlocal +set WINUTILS="%HADOOP_HOME%\bin\winutils.exe" +set TESTDIR=winutils-test + +:: Setup test directory +:: +if not exist %TESTDIR% md %TESTDIR% +pushd %TESTDIR% + +:: Test cases +:: +echo Test case 1: +call:TestChmod "7" "------rwx" +if %ERRORLEVEL% neq 0 goto Failure +echo passed. + +echo Test case 2: +call:TestChmod "70" "---rwx---" +if %ERRORLEVEL% neq 0 goto Failure +echo passed. + +echo Test case 3: +call:TestChmod "u-x,g+r,o=g" "rw-r--r--" +if %ERRORLEVEL% neq 0 goto Failure +echo passed. + +echo Test case 4: +call:TestChmod "u-x,g+rw" "rw-rw----" +if %ERRORLEVEL% neq 0 goto Failure +echo passed. + +echo Test case 5: +call:TestChmod "u-x,g+rwx-x,o=u" "rw-rw-rw-" +if %ERRORLEVEL% neq 0 goto Failure +echo passed. + +echo Test case 6: +call:TestChmodR "755" "rwxr-xr-x" "rwxr-xr-x" +if %ERRORLEVEL% neq 0 goto Failure +echo passed. + +echo Test case 7: +call:TestChmodR "u-x,g+r,o=g" "rw-r--r--" "rw-r--r--" +if %ERRORLEVEL% neq 0 goto Failure +echo passed. + +echo Test case 8: +call:TestChmodR "u-x,g+rw" "rw-rw----" "rw-rw----" +if %ERRORLEVEL% neq 0 goto Failure +echo passed. + +echo Test case 9: +call:TestChmodR "u-x,g+rwx-x,o=u" "rw-rw-rw-" "rw-rw-rw-" +if %ERRORLEVEL% neq 0 goto Failure +echo passed. + +echo Test case 10: +call:TestChmodR "a+rX" "rw-r--r--" "rwxr-xr-x" +if %ERRORLEVEL% neq 0 goto Failure +echo passed. + +echo Test case 11: +call:TestChmod "+" "rwx------" +if %ERRORLEVEL% neq 0 goto Failure +echo passed. + +:: Cleanup +:: +popd +rd %TESTDIR% +goto Success + + +:: ----------------------------------------------------------------------------- +:: -- Function section starts below here +:: ----------------------------------------------------------------------------- + + +:: TestChmod +:: - Test 'chmod' mode or octal mode string of a single file +:: - The new permission will be compared with the expected result +:: +:TestChmod :: [mode|octal mode] [expected permission] +if exist a exit /B 1 +type NUL>a +%WINUTILS% chmod 700 a +%WINUTILS% chmod %~1 a +call:CmpPerm "a" %~2 +if not %ERRORLEVEL% == 0 exit /B 1 +del a +exit /B 0 + + +:: TestChmodR +:: - Test 'chmod' mode or octal mode string with recursive option +:: - The new permission will be compared with the expected results +:: - The permissions could be different due to 'X' in mode string +:: +:TestChmodR :: [mode|octal mode] [expected permission] [expected permission x] +if exist a exit /B 1 +md a +%WINUTILS% chmod 700 a +type NUL>a\a +%WINUTILS% chmod 600 a\a +md a\b +%WINUTILS% chmod 700 a\b +md a\b\a +%WINUTILS% chmod 700 a\b\a +type NUL>a\b\b +%WINUTILS% chmod 600 a\b\b +type NUL>a\b\x +%WINUTILS% chmod u+x a\b\x + +%WINUTILS% chmod -R %~1 a + +call:CmpPerm "a" %~3 +if not %ERRORLEVEL% == 0 exit /B 1 +call:CmpPerm "a\a" %~2 +if not %ERRORLEVEL% == 0 exit /B 1 +call:CmpPerm "a\b" %~3 +if not %ERRORLEVEL% == 0 exit /B 1 +call:CmpPerm "a\b\a" %~3 +if not %ERRORLEVEL% == 0 exit /B 1 +call:CmpPerm "a\b\b" %~2 +if not %ERRORLEVEL% == 0 exit /B 1 +call:CmpPerm "a\b\x" %~3 +if not %ERRORLEVEL% == 0 exit /B 1 + +rd /S /Q a +exit /B 0 + + +:: CmpPerm +:: - Compare file permission against given permission +:: - Use 'ls' to get the new permission +:: - Exit with errorlevel > 0 on failure +:: +:CmpPerm :: [file] [perm] +for /F "tokens=1" %%A in ('call %WINUTILS% ls %~1') do set PERM=%%A +if not %ERRORLEVEL% == 0 exit /B 1 +if not %PERM:~-9%==%~2 exit /B 1 +exit /B 0 + + +:: Failure +:: - Report test failure +:: +:Failure +echo Test failed. +exit /B 1 + +:: Success +:: - Report test success +:: +:Success +echo Test succeeded. +exit /B 0 Added: hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-chown.bat URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-chown.bat?rev=1378794&view=auto ============================================================================== --- hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-chown.bat (added) +++ hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-chown.bat Thu Aug 30 02:34:47 2012 @@ -0,0 +1,95 @@ +:: Licensed to the Apache Software Foundation (ASF) under one or more +:: contributor license agreements. See the NOTICE file distributed with this +:: work for additional information regarding copyright ownership. The ASF +:: licenses this file to you under the Apache License, Version 2.0 (the +:: "License"); you may not use this file except in compliance with the License. +:: You may obtain a copy of the License at +:: +:: http://www.apache.org/licenses/LICENSE-2.0 +:: +:: Unless required by applicable law or agreed to in writing, software +:: distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +:: WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +:: License for the specific language governing permissions and limitations under +:: the License. +:: +@echo off +echo Test chown operations +setlocal +set WINUTILS="%HADOOP_HOME%\bin\winutils.exe" +set TESTDIR=winutils-test + +:: Setup test directory +:: +if not exist %TESTDIR% md %TESTDIR% +pushd %TESTDIR% + +:: Get username +:: +for /F "tokens=1" %%A in ('call whoami') do set USER=%%A + +:: Test cases +:: +echo Test case 1: +if exist a goto Failure +type NUL>a +%WINUTILS% chown %USER%:Administrators a +if not %ERRORLEVEL% == 0 goto Failure +call:CmpOwn "a" "%USER%" "BUILTIN\Administrators" +if not %ERRORLEVEL% == 0 goto Failure +del a +if not %ERRORLEVEL% == 0 goto Failure +echo passed. + +echo Test case 2: +if exist a goto Failure +type NUL>a +%WINUTILS% chown %USER% a +if not %ERRORLEVEL% == 0 goto Failure +%WINUTILS% chown :Administrators a +if not %ERRORLEVEL% == 0 goto Failure +call:CmpOwn "a" "%USER%" "BUILTIN\Administrators" +if not %ERRORLEVEL% == 0 goto Failure +del a +if not %ERRORLEVEL% == 0 goto Failure +echo passed. + + +:: Cleanup +:: +popd +rd %TESTDIR% +goto Success + +:: ----------------------------------------------------------------------------- +:: -- Function section starts below here +:: ----------------------------------------------------------------------------- + +:: CmpOwn +:: - Compare file ownership against expected owner +:: - Use 'ls' to get the ownership +:: - Exit with errorlevel > 0 on failure +:: +:CmpOwn :: [file] [expected user owner] [expected group owner] +for /F "tokens=3" %%A in ('call %WINUTILS% ls %~1') do set OWNER=%%A +if not %ERRORLEVEL% == 0 exit /B 1 +for /F "tokens=4" %%A in ('call %WINUTILS% ls %~1') do set GROUP=%%A +if not %ERRORLEVEL% == 0 exit /B 1 +if /I not %OWNER%==%~2 exit /B 1 +if /I not %GROUP%==%~3 exit /B 1 +exit /B 0 + + +:: Failure +:: - Report test failure +:: +:Failure +echo Test failed. +exit /B 1 + +:: Success +:: - Report test success +:: +:Success +echo Test succeeded. +exit /B 0