Skip to content

Commit fd2ce9a

Browse files
committed
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
2 parents f2856a6 + db292ec commit fd2ce9a

File tree

3 files changed

+67
-11
lines changed

3 files changed

+67
-11
lines changed

src/Common/Commands.Common.Test/Common/ProfileCmdltsTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,20 @@ public void ClearAzureProfileClearsTokenCache()
149149
Assert.Equal(0, tokenCache.ReadItems().Count());
150150
}
151151

152+
[Fact]
153+
public void DeleteCorruptedTokenCache()
154+
{
155+
//setup
156+
string testFileName = @"c:\foobar\TokenCache.dat";
157+
ProfileClient.DataStore.WriteFile(testFileName, new byte[] { 0, 1 });
158+
159+
//Act
160+
ProtectedFileTokenCache tokenCache = new ProtectedFileTokenCache(testFileName);
161+
162+
//Assert
163+
Assert.False(ProfileClient.DataStore.FileExists(testFileName));
164+
}
165+
152166
[Fact]
153167
public void SetAzureSubscriptionAddsSubscriptionWithCertificate()
154168
{

src/Common/Commands.Common/Authentication/ProtectedFileTokenCache.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,39 @@ public static ProtectedFileTokenCache Instance
4444
// Initializes the cache against a local file.
4545
// If the file is already present, it loads its content in the ADAL cache
4646
private ProtectedFileTokenCache()
47+
{
48+
Initialize(CacheFileName);
49+
}
50+
51+
private void Initialize(string fileName)
4752
{
4853
AfterAccess = AfterAccessNotification;
4954
BeforeAccess = BeforeAccessNotification;
5055
lock (fileLock)
5156
{
52-
if (ProfileClient.DataStore.FileExists(CacheFileName))
57+
if (ProfileClient.DataStore.FileExists(fileName))
5358
{
54-
var existingData = ProfileClient.DataStore.ReadFileAsBytes(CacheFileName);
59+
var existingData = ProfileClient.DataStore.ReadFileAsBytes(fileName);
5560
if (existingData != null)
5661
{
57-
Deserialize(ProtectedData.Unprotect(existingData, null, DataProtectionScope.CurrentUser));
62+
try
63+
{
64+
Deserialize(ProtectedData.Unprotect(existingData, null, DataProtectionScope.CurrentUser));
65+
}
66+
catch (CryptographicException)
67+
{
68+
ProfileClient.DataStore.DeleteFile(fileName);
69+
}
5870
}
5971
}
6072
}
6173
}
6274

75+
public ProtectedFileTokenCache(string cacheFile)
76+
{
77+
Initialize(cacheFile);
78+
}
79+
6380
// Empties the persistent store.
6481
public override void Clear()
6582
{
@@ -81,7 +98,14 @@ void BeforeAccessNotification(TokenCacheNotificationArgs args)
8198
var existingData = ProfileClient.DataStore.ReadFileAsBytes(CacheFileName);
8299
if (existingData != null)
83100
{
84-
Deserialize(ProtectedData.Unprotect(existingData, null, DataProtectionScope.CurrentUser));
101+
try
102+
{
103+
Deserialize(ProtectedData.Unprotect(existingData, null, DataProtectionScope.CurrentUser));
104+
}
105+
catch (CryptographicException)
106+
{
107+
ProfileClient.DataStore.DeleteFile(CacheFileName);
108+
}
85109
}
86110
}
87111
}

src/ServiceManagement/HDInsight/Commands.HDInsight/Cmdlet/GetAzureHDInsightJobOutputCmdlet.cs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,21 +136,39 @@ protected override void EndProcessing()
136136
this.command.CurrentSubscription = this.GetCurrentSubscription(this.Subscription, this.Certificate);
137137
this.AssertTaskLogsDirectorySpecified(this.TaskLogsDirectory);
138138

139-
if (this.StandardError.IsPresent)
139+
int numSpecifiedOutputTypes = 0;
140+
string selectedOutputType = "Standard Output";
141+
this.command.OutputType = JobOutputType.StandardOutput;
142+
143+
if (this.StandardOutput.IsPresent)
140144
{
141-
this.command.OutputType = JobOutputType.StandardError;
145+
numSpecifiedOutputTypes++;
142146
}
143-
else if (this.TaskSummary.IsPresent)
147+
148+
if (this.DownloadTaskLogs.IsPresent)
149+
{
150+
this.command.OutputType = JobOutputType.TaskLogs;
151+
selectedOutputType = "Task Logs";
152+
numSpecifiedOutputTypes++;
153+
}
154+
155+
if (this.TaskSummary.IsPresent)
144156
{
145157
this.command.OutputType = JobOutputType.TaskSummary;
158+
selectedOutputType = "Task Summary";
159+
numSpecifiedOutputTypes++;
146160
}
147-
else if (this.DownloadTaskLogs.IsPresent)
161+
162+
if (this.StandardError.IsPresent)
148163
{
149-
this.command.OutputType = JobOutputType.TaskLogs;
164+
this.command.OutputType = JobOutputType.StandardError;
165+
selectedOutputType = "Standard Error";
166+
numSpecifiedOutputTypes++;
150167
}
151-
else
168+
169+
if (numSpecifiedOutputTypes > 1)
152170
{
153-
this.command.OutputType = JobOutputType.StandardOutput;
171+
this.WriteWarning(String.Format("This cmdlet supports specifying only one job output type. Only {0} will be returned", selectedOutputType));
154172
}
155173

156174
try

0 commit comments

Comments
 (0)