• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

google / santa / 10063613345

23 Jul 2024 05:33PM UTC coverage: 63.129% (-0.2%) from 63.284%
10063613345

push

github

web-flow
GUI: Make dismiss button configurable, change default text back to dismiss (#1399)

5620 of 13400 branches covered (41.94%)

Branch coverage included in aggregate %.

6 of 10 new or added lines in 2 files covered. (60.0%)

177 existing lines in 2 files now uncovered.

18831 of 25332 relevant lines covered (74.34%)

7258.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

40.46
/Source/gui/SNTBinaryMessageWindowController.m
1
/// Copyright 2015 Google Inc. All rights reserved.
2
///
3
/// Licensed under the Apache License, Version 2.0 (the "License");
4
/// you may not use this file except in compliance with the License.
5
/// You may obtain a copy of the License at
6
///
7
///    http://www.apache.org/licenses/LICENSE-2.0
8
///
9
///    Unless required by applicable law or agreed to in writing, software
10
///    distributed under the License is distributed on an "AS IS" BASIS,
11
///    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
///    See the License for the specific language governing permissions and
13
///    limitations under the License.
14

15
#import "Source/gui/SNTBinaryMessageWindowController.h"
16

17
#import <MOLCertificate/MOLCertificate.h>
18
#import <SecurityInterface/SFCertificatePanel.h>
19

20
#import "Source/common/CertificateHelpers.h"
21
#import "Source/common/SNTBlockMessage.h"
22
#import "Source/common/SNTConfigurator.h"
23
#import "Source/common/SNTStoredEvent.h"
24

25
@interface SNTBinaryMessageWindowController ()
26
///  The custom message to display for this event
27
@property(copy) NSString *customMessage;
28

29
///  The custom URL to use for this event
30
@property(copy) NSString *customURL;
31

32
///  A 'friendly' string representing the certificate information
33
@property(readonly, nonatomic) NSString *publisherInfo;
34

35
///  An optional message to display with this block.
36
@property(readonly, nonatomic) NSAttributedString *attributedCustomMessage;
37

38
///  Reference to the "Application Name" label in the XIB. Used to remove if application
39
///  doesn't have a CFBundleName.
40
@property(weak) IBOutlet NSTextField *applicationNameLabel;
41

42
@end
43

44
@implementation SNTBinaryMessageWindowController
45

46
- (instancetype)initWithEvent:(SNTStoredEvent *)event
47
                    customMsg:(NSString *)message
48
                    customURL:(NSString *)url {
1✔
49
  self = [super initWithWindowNibName:@"MessageWindow"];
1✔
50
  if (self) {
1!
51
    _event = event;
1✔
52
    _customMessage = message;
1✔
53
    _customURL = url;
1✔
54
    _progress = [NSProgress discreteProgressWithTotalUnitCount:1];
1✔
55
    [_progress addObserver:self
1✔
56
                forKeyPath:@"fractionCompleted"
1✔
57
                   options:NSKeyValueObservingOptionNew
1✔
58
                   context:NULL];
1✔
59
  }
1✔
60
  return self;
1✔
61
}
1✔
62

63
- (void)dealloc {
×
64
  [_progress removeObserver:self forKeyPath:@"fractionCompleted"];
×
65
}
×
66

67
- (void)observeValueForKeyPath:(NSString *)keyPath
68
                      ofObject:(id)object
69
                        change:(NSDictionary *)change
70
                       context:(void *)context {
×
71
  if ([keyPath isEqualToString:@"fractionCompleted"]) {
×
72
    dispatch_async(dispatch_get_main_queue(), ^{
×
73
      NSProgress *progress = object;
×
74
      if (progress.fractionCompleted != 0.0) {
×
75
        self.hashingIndicator.indeterminate = NO;
×
76
      }
×
77
      self.hashingIndicator.doubleValue = progress.fractionCompleted;
×
78
    });
×
79
  }
×
80
}
×
81

82
- (void)loadWindow {
1✔
83
  [super loadWindow];
1✔
84
  NSURL *url = [SNTBlockMessage eventDetailURLForEvent:self.event customURL:self.customURL];
1✔
85

86
  if (!url) {
1!
87
    [self.openEventButton removeFromSuperview];
1✔
88
  } else if (self.customURL.length == 0) {
1!
89
    // Set the button text only if a per-rule custom URL is not used. If a
90
    // custom URL is used, it is assumed that the `EventDetailText` config value
91
    // does not apply and the default text will be used.
92
    NSString *eventDetailText = [[SNTConfigurator configurator] eventDetailText];
×
93
    if (eventDetailText) {
×
94
      [self.openEventButton setTitle:eventDetailText];
×
95
      // Require the button keyEquivalent set to be CMD + Return
96
      [self.openEventButton setKeyEquivalent:@"\r"];  // Return Key
×
97
      [self.openEventButton
×
98
        setKeyEquivalentModifierMask:NSEventModifierFlagCommand];  // Command Key
×
99
    }
×
100
  }
×
101

102
  NSString *dismissButtonText = [[SNTConfigurator configurator] dismissText];
1✔
103
  if (dismissButtonText.length) {
1!
NEW
104
    [self.dismissEventButton setTitle:dismissButtonText];
×
NEW
105
  }
×
106

107
  if (!self.event.needsBundleHash) {
1!
108
    [self.bundleHashLabel removeFromSuperview];
1✔
109
    [self.hashingIndicator removeFromSuperview];
1✔
110
    [self.foundFileCountLabel removeFromSuperview];
1✔
111
  } else {
1✔
112
    self.openEventButton.enabled = NO;
×
113
    self.hashingIndicator.indeterminate = YES;
×
114
    [self.hashingIndicator startAnimation:self];
×
115
    self.bundleHashLabel.hidden = YES;
×
116
    self.foundFileCountLabel.stringValue = @"";
×
117
  }
×
118

119
  if (!self.event.fileBundleName) {
1!
120
    [self.applicationNameLabel removeFromSuperview];
×
121
  }
×
122
}
1✔
123

124
- (NSString *)messageHash {
1✔
125
  return self.event.fileSHA256;
1✔
126
}
1✔
127

128
- (IBAction)showCertInfo:(id)sender {
×
129
  // SFCertificatePanel expects an NSArray of SecCertificateRef's
130
  [[[SFCertificatePanel alloc] init] beginSheetForWindow:self.window
×
131
                                           modalDelegate:nil
×
132
                                          didEndSelector:nil
×
133
                                             contextInfo:nil
×
134
                                            certificates:CertificateChain(self.event.signingChain)
×
135
                                               showGroup:YES];
×
136
}
×
137

138
- (IBAction)openEventDetails:(id)sender {
×
139
  NSURL *url = [SNTBlockMessage eventDetailURLForEvent:self.event customURL:self.customURL];
×
140

141
  [self closeWindow:sender];
×
142
  [[NSWorkspace sharedWorkspace] openURL:url];
×
143
}
×
144

145
#pragma mark Generated properties
146

147
+ (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key {
9✔
148
  if (![key isEqualToString:@"event"]) {
9✔
149
    return [NSSet setWithObject:@"event"];
4✔
150
  } else {
5✔
151
    return [NSSet set];
5✔
152
  }
5✔
153
}
9✔
154

155
- (NSString *)publisherInfo {
2✔
156
  return Publisher(self.event.signingChain, self.event.teamID);
2✔
157
}
2✔
158

159
- (NSAttributedString *)attributedCustomMessage {
1✔
160
  return [SNTBlockMessage attributedBlockMessageForEvent:self.event
1✔
161
                                           customMessage:self.customMessage];
1✔
162
}
1✔
163

164
- (void)updateBlockNotification:(SNTStoredEvent *)event withBundleHash:(NSString *)bundleHash {
×
165
  // UI updates must happen on the main thread.
166
  dispatch_async(dispatch_get_main_queue(), ^{
×
167
    if ([self.event.idx isEqual:event.idx]) {
×
168
      if (bundleHash) {
×
169
        [self.bundleHashLabel setHidden:NO];
×
170
      } else {
×
171
        [self.bundleHashLabel removeFromSuperview];
×
172
        [self.bundleHashTitle removeFromSuperview];
×
173
      }
×
174
      self.event.fileBundleHash = bundleHash;
×
175
      [self.foundFileCountLabel removeFromSuperview];
×
176
      [self.hashingIndicator setHidden:YES];
×
177
      [self.openEventButton setEnabled:YES];
×
178
    }
×
179
  });
×
180
}
×
181

182
@end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc